c# - IPv6: Why changing ScopeId of System.Net.IPAddress is not reflected at ToString() representation? -
yesterday met thing seems .net bug.
ipaddress addr = ipaddress.parse("fe80::1111:2222:abc%11"); // scopeid 11 string s1 = addr.tostring(); // see fe80::1111:2222:abc%11 addr.scopeid = 0; // scopeid 0 string s2 = addr.tostring(); // expect see fe80::1111:2222:abc why s1 same content s2 after scopeid changed? in debugger watch window see scope value changed. internal string field has no impact.
for sure, tried various ipv6 addresses , different scope ids - behavior same. have missed?
i call bug in .net framework.
if @ source code ipaddress class:
http://referencesource.microsoft.com/#system/net/system/net/ipaddress.cs
you'll see .tostring() method caches results private field called m_tostring. however, if @ setter scopeid property, see changes private fields m_scopeid , m_address, not clear m_tostring value.
if @ address property, you'll see clear m_tostring field when property set.
if want work around, can did here:
how determine equality between 2 ipv6 addresses?
by using .getaddressbytes() method pass constructor create new instance. give scopeid of zero.
Comments
Post a Comment