سؤال

While hacking some data into my settings.settings in VS 2010, i discovered i can use many different types from a variety of libraries i use, for example, the HTTPListener from the System.Net-namespace.

But for some strange reason i can't see why, i can't use the IPAddress-type, which i need actually. Why is this so and how can i fix this, since for me, this is nothing more than an annoying bug.

I don't know what to try to fix this?

هل كانت مفيدة؟

المحلول

System.Net.IPAddress has the Serializable-Attribute

That's not relevant, [Serializable] only matters to binary serialization. Settings are serialized with XML serialization. Which is the core problem, that only works when the type has a default constructor. So the deserializer can create a new object and set the public fields and properties. IPAddress doesn't have one.

Consider using a simple string instead. Use IPAddress.Parse() and ToString() in your code to convert.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top