C# The attempted operation is not supported for the type of object referenced

…衆ロ難τιáo~ 提交于 2019-12-13 01:24:14

问题


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:


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



来源:https://stackoverflow.com/questions/10631615/c-sharp-the-attempted-operation-is-not-supported-for-the-type-of-object-referenc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!