S
Softlion
Hi,
I've a class MyElement which represents a configuration element, so as .NET
2 it derives from ConfigurationElement.
I would like to create an instance of MyElement using a XML stream I loaded
from an external source (which is not a configuration file).
I tryed to use XmlSerializer like this :
XmlSerializer mySerializer = new XmlSerializer( typeof(
Settings.MyElement ) );
StreamWriter myWriter = new StreamWriter( @"c:\MyElement.xml" );
mySerializer.Serialize( myWriter, myObjectOfTypeMyElement );
myWriter.Close();
But it won't work complaining about the public field
ConfigurationLockCollection from the ConfigurationElement class not being
serializable !!
{System.InvalidOperationException: There was an error reflecting type
'App.MyElement'. ---> System.InvalidOperationException: You must implement a
default accessor on System.Configuration.ConfigurationLockCollection because
it inherits from ICollection.
at System.Xml.Serialization.TypeScope.GetDefaultIndexer(Type type, String
memberInfo).
......
Do I have to implement my own IXmlSerializer on the class ? But will it
still work as a configuration element ? Any other mean to do that ?
What a bad idead to have to derive from a framewrok class for the
configuration !!!! Microsoft team should change that again in the next
version.
I've a class MyElement which represents a configuration element, so as .NET
2 it derives from ConfigurationElement.
I would like to create an instance of MyElement using a XML stream I loaded
from an external source (which is not a configuration file).
I tryed to use XmlSerializer like this :
XmlSerializer mySerializer = new XmlSerializer( typeof(
Settings.MyElement ) );
StreamWriter myWriter = new StreamWriter( @"c:\MyElement.xml" );
mySerializer.Serialize( myWriter, myObjectOfTypeMyElement );
myWriter.Close();
But it won't work complaining about the public field
ConfigurationLockCollection from the ConfigurationElement class not being
serializable !!
{System.InvalidOperationException: There was an error reflecting type
'App.MyElement'. ---> System.InvalidOperationException: You must implement a
default accessor on System.Configuration.ConfigurationLockCollection because
it inherits from ICollection.
at System.Xml.Serialization.TypeScope.GetDefaultIndexer(Type type, String
memberInfo).
......
Do I have to implement my own IXmlSerializer on the class ? But will it
still work as a configuration element ? Any other mean to do that ?
What a bad idead to have to derive from a framewrok class for the
configuration !!!! Microsoft team should change that again in the next
version.