PC Review


Reply
Thread Tools Rate Thread

Deserialize a ConfigurationElement derived class myself ?

 
 
Softlion
Guest
Posts: n/a
 
      22nd Jul 2006
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.




 
Reply With Quote
 
 
 
 
Softlion
Guest
Posts: n/a
 
      22nd Jul 2006
Ok I've implemented the ISerializable interface and it works with both Xml
serialization and Configuration element serialization.

Thanks Microsoft teams for helping us NOT programming 2 times the same thing
....


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
IXmlSerializable - Deserialize class with class references Jamie Microsoft C# .NET 0 31st Jul 2006 07:26 PM
Instance of derived class does not show public methods or properties that are not in the inherited class D Witherspoon Microsoft Dot NET 5 28th Mar 2006 11:25 PM
Instance of derived class does not show public methods or properties that are not in the inherited class D Witherspoon Microsoft VB .NET 5 28th Mar 2006 11:25 PM
Re: Setting an Event Handler on data member of parent class in derived class Jon Skeet [C# MVP] Microsoft C# .NET 1 13th Jan 2006 07:30 AM
RE: Framework 1.1 bug. Derived class generating Abstract base class stubs. Sometimes. MSFT Microsoft VB .NET 3 4th Nov 2003 06:53 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:38 PM.