C
C#16mo ago
Pillow

System.InvalidOperationException: ... cannot be serialized because it does not have a parameterles..

I'm trying to make an AOT class library, but I am unable to run it once compiled. Here's the bit of code it doesn't like
var parser = new TMXParser();
parser.Export(tmx, tmxpath);
var parser = new TMXParser();
parser.Export(tmx, tmxpath);
and the full error:
Unhandled Exception: System.InvalidOperationException: There was an error generating the XML document.
---> System.InvalidOperationException: TMXTile.TMXMap cannot be serialized because it does not have a parameterless constructor.
at System.Xml.Serialization.TypeDesc.CheckSupported() + 0x44
at System.Xml.Serialization.TypeScope.GetTypeDesc(Type, MemberInfo, Boolean, Boolean) + 0xa5
at System.Xml.Serialization.ModelScope.GetTypeModel(Type, Boolean) + 0x5a
at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(Type, XmlRootAttribute, String) + 0x50
at System.Xml.Serialization.XmlSerializer.GetMapping() + 0x4f
at System.Xml.Serialization.XmlSerializer.SerializeUsingReflection(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id) + 0x1a
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id) + 0x84
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id) + 0x1a8
at TMXTile.TMXParser.Export(TMXMap, Stream, DataEncodingType) + 0x97
at TMXTile.TMXParser.Export(TMXMap, String, DataEncodingType) + 0x73
at ToasterMap.ToasterMap.Init(IntPtr, IntPtr) + 0xef
Unhandled Exception: System.InvalidOperationException: There was an error generating the XML document.
---> System.InvalidOperationException: TMXTile.TMXMap cannot be serialized because it does not have a parameterless constructor.
at System.Xml.Serialization.TypeDesc.CheckSupported() + 0x44
at System.Xml.Serialization.TypeScope.GetTypeDesc(Type, MemberInfo, Boolean, Boolean) + 0xa5
at System.Xml.Serialization.ModelScope.GetTypeModel(Type, Boolean) + 0x5a
at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(Type, XmlRootAttribute, String) + 0x50
at System.Xml.Serialization.XmlSerializer.GetMapping() + 0x4f
at System.Xml.Serialization.XmlSerializer.SerializeUsingReflection(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id) + 0x1a
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id) + 0x84
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id) + 0x1a8
at TMXTile.TMXParser.Export(TMXMap, Stream, DataEncodingType) + 0x97
at TMXTile.TMXParser.Export(TMXMap, String, DataEncodingType) + 0x73
at ToasterMap.ToasterMap.Init(IntPtr, IntPtr) + 0xef
13 Replies
mtreit
mtreit16mo ago
The error is telling you exactly what the issue is. The type you are trying to serialize needs a parameterless constructor Because the serializer uses that to construct an empty instance and then set the properties / fields.
Pillow
PillowOP16mo ago
do I not have one right there tho?
mtreit
mtreit16mo ago
The type in the error is TMXMap not TMXParser
Pillow
PillowOP16mo ago
I don't think TMXMap has a constructor tho
mtreit
mtreit16mo ago
That's exactly why you're getting the error. It doesn't have one. But if you want to serialize it, it has to have one.
Pillow
PillowOP16mo ago
so I just can't use that library at all?
mtreit
mtreit16mo ago
I take it that it's not something you wrote yourself?
Pillow
PillowOP16mo ago
correct
mtreit
mtreit16mo ago
If you don't own the type and it doesn't provide a parameterless constructor, I don't think there is a good way for you to serialize it with XmlSerializer.
Pillow
PillowOP16mo ago
oh so I just.. can't do it?
mtreit
mtreit16mo ago
I'm not sure what your code actually does, but the error says you are trying to serialize that type with XmlSerializer and that is simply not possible.
Pillow
PillowOP16mo ago
ah
Accord
Accord16mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server