Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XmlSerializer now serializes properties of object type properly #2796

Merged
merged 1 commit into from Aug 16, 2015

Conversation

hmemcpy
Copy link
Contributor

@hmemcpy hmemcpy commented Aug 13, 2015

Who's affected

Users with V5.X endpoints configured to use XML message serialization, when using fields of type System.Object that are assigned primitive or simple (e.g. Guid, DateTime) types.

Symptoms

Serialization will not generate namespaces for simple types, and deserialization will fail, since the message element does not have all the appropriate namespaces.

Steps to reproduce

Trying to serialize, then deserialize the following type fill fail, when the Value property is assigned a simple type, e.g. Guid:

public class SerializedPair
{
    public string Key { get; set; }
    public object Value { get; set; }
}

Workaround

none

Original bug report

I'm currently upgrading from NServiceBus 4.7.5 to NServiceBus 5.2.4, and when using the XmlSerializer, I noticed that it generates an invalid XML message when I try to serialize a message -
the namespaces for the simple types are no longer declared, but they're still used in the document.

For example, if I try to serialize a message that exposes a SerializedPair property that is defined as follows:

public class SerializedPair
{
    public string Key { get; set; }
    public object Value { get; set; }
}

in 4.7.5 it would be serialized as:

<?xml version="1.0"?>
<Messages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
          xmlns="http://tempuri.net/xxx.Crm.ServiceBusMessages" 
          xmlns:guid="Guid" xmlns:int32="Int32" 
          xmlns:string="String" 
          xmlns:datetime="DateTime" 
          xmlns:boolean="Boolean" 
          xmlns:decimal="Decimal">
    <UpdateContact>
        <SerializedPair>
            <Key>AddressId</Key>
            <guid:Value>ebdeeb33-baa7-4100-b1aa-eb4d6816fd3d</guid:Value>
        </SerializedPair>
       ....

In 5.2.4, it gets serialized as:

<?xml version="1.0" ?>
<UpdateContact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
               xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
               xmlns="http://tempuri.net/xxx.Crm.ServiceBusMessages">
    <SerializedPair>
        <Key>AddressId</Key>
        <guid:Value>70a22cd7-64fd-4d6d-ab13-2ad7800addc7</guid:Value>
    </SerializedPair>
    ....

Note that the "Messages" element is no longer present, and the "xmlns:guid" namespace declaration is also missing, which makes this invalid XML.
How do I get NServiceBus to generate valid xml again?

For completeness, my BusConfiguration looks like:

BusConfiguration busConfiguration = new BusConfiguration();
busConfiguration.UseSerialization<XmlSerializer>();
busConfiguration.UseTransport<MsmqTransport>();
ISendOnlyBus bus = Bus.CreateSendOnly(busConfiguration);

This was originally posted in http://stackoverflow.com/q/31943814/90882

@johnsimons johnsimons added the Bug label Aug 11, 2015
@andreasohlund
Copy link
Member

Messages root beening gone is fine but the namespace issue seems like a critical bug to me

@hmemcpy hmemcpy self-assigned this Aug 12, 2015
@hmemcpy hmemcpy added this to the 5.2.5 milestone Aug 12, 2015
@andreasohlund andreasohlund changed the title NServiceBus generates XML message without simple type namespaces XmlSerializer now serializes properties of object type properly Aug 13, 2015
@andreasohlund
Copy link
Member

@hmemcpy updating description to point out that it only affects V5 endpoints

hmemcpy added a commit that referenced this pull request Aug 16, 2015
XmlSerializer now serializes properties of `object` type properly
@hmemcpy hmemcpy merged commit d90cb83 into master Aug 16, 2015
@hmemcpy hmemcpy deleted the hotfix-5.2.5 branch August 16, 2015 08:49
@hmemcpy hmemcpy restored the hotfix-5.2.5 branch August 16, 2015 08:49
@hmemcpy hmemcpy deleted the hotfix-5.2.5 branch October 14, 2015 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants