You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Asp.Net Blazor WASM based client has issues using the DataContractSerializer. DataContractSerializer.ReadObject correctly reads an object when run via visual studio but when published fails throwing an exception.
Observe that the main index page shows 'No Exception'.
Publish the client and copy the files to a web server and browse to the published location.
Observe the page displays a stack trace shown the DataContractSerializer.ReadObject failing.
It appears that property de-serialisation using a bool, bool? and int property types triggers the issue, a string property data type doesn't. Note that I haven't tested the full range of CLR types.
The following stack trace is generated:
System.NullReferenceException: Arg_NullReferenceException
at System.Runtime.Serialization.CodeGenerator.Call(MethodInfo methodInfo)
at System.Runtime.Serialization.XmlFormatReaderGenerator.CriticalHelper.ThrowValidationException()
at System.Runtime.Serialization.XmlFormatReaderGenerator.CriticalHelper.ThrowValidationException(String msg, Object[] values)
at System.Runtime.Serialization.XmlFormatReaderGenerator.CriticalHelper.ReadValue(Type type, String name, String ns)
at System.Runtime.Serialization.XmlFormatReaderGenerator.CriticalHelper.ReadMembers(ClassDataContract classContract, Boolean[] requiredMembers, Label[] memberLabels, LocalBuilder memberIndexLocal, LocalBuilder requiredIndexLocal)
at System.Runtime.Serialization.XmlFormatReaderGenerator.CriticalHelper.ReadMembers(ClassDataContract classContract, LocalBuilder extensionDataLocal)
at System.Runtime.Serialization.XmlFormatReaderGenerator.CriticalHelper.ReadClass(ClassDataContract classContract)
at System.Runtime.Serialization.XmlFormatReaderGenerator.CriticalHelper.GenerateClassReader(ClassDataContract classContract)
at System.Runtime.Serialization.XmlFormatReaderGenerator.GenerateClassReader(ClassDataContract classContract)
at System.Runtime.Serialization.ClassDataContract.CreateXmlFormatReaderDelegate()
at System.Runtime.Serialization.ClassDataContract.get_XmlFormatReaderDelegate()
at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
at System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract)
at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, DataContract dataContract, String name, String ns)
at System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName)
at System.Runtime.Serialization.DataContractSerializer.ReadObject(XmlReader reader, Boolean verifyObjectName)
at DataContractIssue.DeseriliseIssue.TryCreateIssue()
I've found a similar but different stack trace with de-serialisation of other class types:
Exception during login process: System.NullReferenceException: Arg_NullReferenceException
at System.Runtime.Serialization.CodeGenerator.VerifyParameterCount(MethodInfo methodInfo, Int32 expectedCount)
at System.Runtime.Serialization.CodeGenerator.Call(Object thisObj, MethodInfo methodInfo, Object param1)
at System.Runtime.Serialization.XmlFormatReaderGenerator.CriticalHelper.CreateObject(ClassDataContract classContract)
at System.Runtime.Serialization.XmlFormatReaderGenerator.CriticalHelper.GenerateClassReader(ClassDataContract classContract)
at System.Runtime.Serialization.XmlFormatReaderGenerator.GenerateClassReader(ClassDataContract classContract)
at System.Runtime.Serialization.ClassDataContract.CreateXmlFormatReaderDelegate()
at System.Runtime.Serialization.ClassDataContract.get_XmlFormatReaderDelegate()
at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
at System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract)
at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, DataContract dataContract, String name, String ns)
at System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName)
at System.Runtime.Serialization.DataContractSerializer.ReadObject(XmlDictionaryReader reader, Boolean verifyObjectName)
Illustrative code
stringmessage;varserialiser=newDataContractSerializer(typeof(AuthOutcome),newDataContractSerializerSettings());using(varoutput=newStringWriter())using(varwriter=newXmlTextWriter(output){Formatting=Formatting.None}){serialiser.WriteObject(writer,newAuthOutcome());message=output.GetStringBuilder().ToString();}usingvarreader=XmlReader.Create(newStringReader(message));// the following line causes an exception to be thrown when running with published codeserialiser.ReadObject(reader,false);publicclassAuthOutcome{publicboolPropertyTriggeringIssue{get;set;}}
The example given here does not throw an exception. More complex scenarios such as de-serialising a type hierarchy still have issues though with the following exception thrown:
System.BadImageFormatException: Method has zero rva
at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
at System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract)
at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 id, RuntimeTypeHandle declaredTypeHandle, String name, String ns)
at System.Runtime.Serialization.CollectionDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
at System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract)
at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 id, RuntimeTypeHandle declaredTypeHandle, String name, String ns)
at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
at System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract)
at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 id, RuntimeTypeHandle declaredTypeHandle, String name, String ns)
at System.Runtime.Serialization.CollectionDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
at System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract)
at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, DataContract dataContract, String name, String ns)
at System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName)
at System.Runtime.Serialization.DataContractSerializer.ReadObject(XmlDictionaryReader reader, Boolean verifyObjectName)
The text was updated successfully, but these errors were encountered:
@lewing I can create a similar issue listed at the end in the Remarks section with BlazorWebassemblyEnableLinking set to false and within a debug launch from VS. Is it worth trying to create a sample for this, or is it likely the changes will fix all these type of issues and its best waiting?
Description
A Asp.Net Blazor WASM based client has issues using the DataContractSerializer. DataContractSerializer.ReadObject correctly reads an object when run via visual studio but when published fails throwing an exception.
An example is available from the following repo: https://github.com/allderidge/BlazorBugReport_DataContractIssue
To reproduce the issue:
It appears that property de-serialisation using a bool, bool? and int property types triggers the issue, a string property data type doesn't. Note that I haven't tested the full range of CLR types.
The following stack trace is generated:
I've found a similar but different stack trace with de-serialisation of other class types:
Illustrative code
Configuration
5.0.0-preview.8.20414.8
dotnet --info
Microsoft Visual Studio Enterprise 2019 Preview Version 16.8.0 Preview 2.1
Remarks
Preventing linking by adding the following properties to the project file helps:
The example given here does not throw an exception. More complex scenarios such as de-serialising a type hierarchy still have issues though with the following exception thrown:
The text was updated successfully, but these errors were encountered: