Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
312 views
in Technique[技术] by (71.8m points)

c# - XmlSerializer breaks on .Net 5 upgrade

We have a set of classes which we obtained via xsd.exe and we use to serialize/deserialize some XML. We were using this on .NET 4.7.2 and everything went well. Once we tried to upgrade to .NET 5, some is working ok but other classes are failing on the XMLSerializer constructor with the following error:

System.PlatformNotSupportedException: Compiling JScript/CSharp scripts is not supported

I've searched for this error but I only got results regarding WCF. Does anyone know if something might have changed in XMLSerializer that can provoke this error?

question from:https://stackoverflow.com/questions/65844061/xmlserializer-breaks-on-net-5-upgrade

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I found the problem. I leave the answer here for if it helps someone. We had a property like this:

/// <remarks/>
[XmlElement("EstimatedEndDateTime", typeof(System.DateTime), Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
[XmlElement("FinalizedEndDateTime", typeof(System.DateTime), Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
[XmlChoiceIdentifier("ItemElementName")]
public System.DateTime? Item
{
    get
    {
        return this.itemField;
    }
    set
    {
        this.itemField = value;
    }
}

I had to change the type in the XmlElement attributes to be also System.DateTime?. The weird thing is that it used to work with .Net 4.7.2.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...