Skip to content

Exception when deserializing the result message after updating SoapCore #1161

@cosmo0

Description

@cosmo0

We have an app that was working with SoapCore 1.2.0, and is breaking with version 1.2.1.11. I have rolled back and it works with 1.2.0.1 but it breaks as soon as 1.2.1.0.

One of our middleware is crashing during the call to the "next" with the following error:

Type 'System.Xml.XmlAttribute' is an invalid collection type since it does not have a valid Add method with parameter of type 'System.Object'.

And the stacktrace:

   at System.Runtime.Serialization.DataContracts.DataContract.DataContractCriticalHelper.ThrowInvalidDataContractException(String message, Type type)
   at System.Runtime.Serialization.DataContracts.CollectionDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)
   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)
   at System.Runtime.Serialization.DataContracts.CollectionDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)
   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)
   at System.Runtime.Serialization.DataContracts.ClassDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)
   at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)
   at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectContentHandleExceptions(XmlWriterDelegator writer, Object graph)
   at System.ServiceModel.Channels.XmlObjectSerializerHeader.OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
   at System.ServiceModel.Channels.MessageHeader.WriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
   at System.ServiceModel.Channels.MessageHeaders.WriteHeaderContents(Int32 headerIndex, XmlDictionaryWriter writer)
   at System.ServiceModel.Channels.MessageHeaders.WriteHeader(Int32 headerIndex, XmlDictionaryWriter writer)
   at System.ServiceModel.Channels.Message.WriteMessagePreamble(XmlDictionaryWriter writer)
   at System.ServiceModel.Channels.Message.OnWriteMessage(XmlDictionaryWriter writer)
   at System.ServiceModel.Channels.Message.WriteMessage(XmlDictionaryWriter writer)
   at System.ServiceModel.Channels.Message.WriteMessage(XmlWriter writer)
   at SoapCore.MessageEncoder.SoapMessageEncoder.<WriteMessageAsync>d__41.MoveNext()
   at SoapCore.SoapEndpointMiddleware`1.<ProcessOperation>d__15.MoveNext()
   at SoapCore.SoapEndpointMiddleware`1.<Invoke>d__10.MoveNext()
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<<Invoke>g__AwaitRequestTask|7_0>d.MoveNext()
   at MyMiddleware.<Invoke>d__4.MoveNext() in MyMiddleware.cs

The middleware in question looks like (very simplified):

public partial class MyMiddleware
{
    private readonly RequestDelegate _next;

    public MyMiddleware(RequestDelegate next)
    {
        _next = next;
    }
    
    public async Task Invoke(HttpContext context) {
        // snip: do some stuff

        await _next(context); // this is the line crashing

        // snip: do some other stuff
    }
}

I can't really give you the response object, it's in a generated file that is 87175 lines long and the object is supposed to be composed of objects... Let me know how I can pinpoint the offending object or property, as I don't see anything in the exception that would help me figure it out.

Note that our request handler works fine and processes the request; the crash happens during serialization of the response.

Comparing the last working version with the newest non-working I don't find any change in SoapMessageEncoder.WriteMessageAsync so I'm not sure what's going on.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions