C# The attempted operation is not supported for th

2019-07-25 19:54发布

I got this error when I tried to parse an IP address that was in string form.

I was using a public dns ip address (4.2.2.2) while testing this (using the System.Net's IPAddress.Parse method).

It does the parsing correctly and returns an IPAddress object. However, if I try to access the ScopeId property of this object, a SocketException is thrown with the message given in the title.

I really am not able to figure out whats the problem here. When I checked the documentation of IPAddress.ScopeId property, it says an exception is thrown when AddressFamily=InterNetwork which is the case with my example.

Could someone please explain the reason for this.

1条回答
该账号已被封号
2楼-- · 2019-07-25 20:41

ScopeID is an IPv6 specific field. You have an IPv4 address. Therefore, an exception is raised. InterNetwork in this case means IPv4.

查看更多
登录 后发表回答