2

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?

Carles Company
  • 6,905
  • 5
  • 49
  • 72
  • 2
    Can you share a [mcve]? – mjwills Jan 22 '21 at 11:14
  • I'll try to come up with a reproduced example as I cannot share the code. – Carles Company Jan 22 '21 at 11:19
  • 1
    Take a look at [this question](https://stackoverflow.com/questions/54201877/platformnotsupportedexception-xslcompiledtransform-loadxslt-not-loading-the). If you have a xlst using a javascript or C# code for transformation, that may be the issue. – Magnetron Jan 22 '21 at 11:54
  • Ok. I found the problem. It looks as if some property had a different type in the attribute than in the property itsel (DateTime vs DateTime?). The weird thing is that this worked and now it does not... – Carles Company Jan 22 '21 at 13:33

1 Answers1

0

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.

Carles Company
  • 6,905
  • 5
  • 49
  • 72
  • The same root cause as here https://stackoverflow.com/questions/60976792/net-core-3-1-soap-platform-not-supported-error-compiling-jscript-csharp-script Looks like the rules are now strict. – FireAlkazar Jan 22 '21 at 13:41