1
Error : System.Xml.Linq.XAttribute cannot be serialized because it does not have a parameterless constructor.
Question asked by Scott Zrubek - 3/5/2020 at 4:16 PM
Answered
I've taken my XSD and generated classes from it using liquid's tool.  I then split all of the classes out into individual files.  When I attempt to serialize the main class, I get the following error

InvalidOperationException: System.Xml.Linq.XAttribute cannot be serialized because it does not have a parameterless constructor.

I've removed/commented out all of the attributes for the main class (it does extend another class which I've kept untouched for the moment) it still generates the same error.  

The line of code generating the error is:

XmlSerializer serializer = new XmlSerializer(typeof(SpaceSystemTypeCtDTO));
Any thoughts, suggestions, ideas?

3 Replies

Reply to Thread
0
Liquid Support Replied
Employee Post Marked As Answer
You shouldn't be using XmlSerializer, please see the documentation:

LxSerializer<BookstoreElm> serializer = new LxSerializer<BookstoreElm>();
BookstoreElm bookstore = serializer.Deserialize(@"..\..\BookstoreSample.xml");
0
Scott Zrubek Replied
I discovered that and it's working fine.  Unfortunately, I need the ability to handle attributes that are not in the standard XSD.  In the regular Serializer there is the UnknownAttribute event.  Does such an option, or something similar, exist with the LxSerializer?
0
Liquid Support Replied
Employee Post
Yes, please see the Liquid XML Objects documentation regarding Unexpected Elements and Attributes

If 'Handle unknown nodes' option is true, any unexpected elements and attributes will be processed and added to a generic list of XElements and XAttributes.

If 'Handle unknown nodes' option is false, any unexpected elements and attributes will cause the error handler to be invoked.

Reply to Thread