MarimerLLC / csla

A home for your business logic in any .NET application.
https://cslanet.com
MIT License
1.25k stars 402 forks source link

Unable to deserialize object #3680

Closed oskarjf closed 7 months ago

oskarjf commented 7 months ago

Describe the bug I've a XML string that I need to deserialize. The XML contains an array of objects that inherit from BusinessBase. I'm using System.Xml.Serialization.XmlSerializer to deserialize the string and I'm getting an exception:

 System.InvalidOperationException
  HResult=0x80131509
  Message=Cannot deserialize type 'Csla.Rules.BrokenRule' because it contains property 'RuleName' which has no public setter.

Version and Platform CSLA version: 5.5.3 OS: Windows Platform: ASP.NET Core 8.0

Code that Fails new XmlSerializer(type1, extraTypes) where extraTypes contains an array of types where one of the types are inheriting from BusinessBase

Stack Trace or Exception Detail

System.InvalidOperationException
  HResult=0x80131509
  Message=Cannot deserialize type 'Csla.Rules.BrokenRule' because it contains property 'RuleName' which has no public setter.
  Source=System.Private.Xml
  StackTrace:
   at System.Xml.Serialization.TypeScope.GetSettableMembers(StructMapping mapping, List`1 list)
   at System.Xml.Serialization.TypeScope.GetSettableMembers(StructMapping structMapping)
   at System.Xml.Serialization.XmlSerializationReaderILGen.WriteLiteralStructMethod(StructMapping structMapping)
   at System.Xml.Serialization.XmlSerializationReaderILGen.GenerateMethod(TypeMapping mapping)
   at System.Xml.Serialization.XmlSerializationILGen.GenerateReferencedMethods()
   at System.Xml.Serialization.XmlSerializationReaderILGen.GenerateEnd()
   at System.Xml.Serialization.TempAssembly.GenerateRefEmitAssembly(XmlMapping[] xmlMappings, Type[] types)
   at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location)
   at System.Xml.Serialization.XmlSerializer.GenerateTempAssembly(XmlMapping xmlMapping, Type type, String defaultNamespace, String location)
   at System.Xml.Serialization.XmlSerializer..ctor(Type type, Type[] extraTypes)

Additional context The XML string I'm deserializing is coming from an external app.

oskarjf commented 7 months ago

Is the issue that I'm running an old version of CSLA?

rockfordlhotka commented 7 months ago

This might help:

https://github.com/MarimerLLC/csla/blob/main/docs/serialization.md