Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9297791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:09:36+00:00 2026-06-18T22:09:36+00:00

I’m having a frustrating time with C# message serialization. I have a class which

  • 0

I’m having a frustrating time with C# message serialization.
I have a class which has a constructor which looks like this:

public ProposalRequestMessage(int imaNumber, int proposalId, bool trainingFlag, string firstSiteAddress,
                                  bool lastSiteFlag, string lastSiteAddress, int reasonCode,
                                  List<LaneSelection> theLaneSelections)
    {
        ImaNumber = imaNumber;
        ProposalId = proposalId;
        TrainingFlag = trainingFlag;
        FirstSiteAddress = firstSiteAddress;
        LastSiteFlag = lastSiteFlag;
        LastSiteAddress = lastSiteAddress;
        ReasonCode = reasonCode;
        laneSelections = new List<LaneSelection>(theLaneSelections);
    }

The lanesSelections member of the class of of type System.Collections.Generic.List, where a LaneSelection looks like this:

public class LaneSelection
{
    public int LaneId { get; set; }
    public SignalAspect AspectCode { get; set; }

    public LaneSelection()
    {
    }
    public LaneSelection(int laneId, SignalAspect aspectCode)
    {
        LaneId = laneId;
        AspectCode = aspectCode;
    }
}  

A SignalAspect is an enumeration.

I send a message containing an instance of this class over an MSMQ as follows:

System.Messaging.MessageQueue queue = new System.Messaging.MessageQueue(queuename);
        queue.Purge();

System.Messaging.Message msg = new System.Messaging.Message(theMessage, new System.Messaging.XmlMessageFormatter());
        queue.Send(msg);

Using some debug tools, I have found that the resulting XML looks a bit like this:

<?xml version="1.0"?>
<IvtmMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">  
<MessageType>ProposalRequest</MessageType>  
<ProposalRequestMessage>    
    <ImaNumber>0</ImaNumber>    
    <ProposalId>2</ProposalId>    
    <TrainingFlag>false</TrainingFlag>    
    <FirstSiteAddress>M25/4690A</FirstSiteAddress>    
    <LastSiteFlag>false</LastSiteFlag>    
    <LastSiteAddress />    
    <ReasonCode>3</ReasonCode>    
    <LaneSelections>      
        <LaneSelection>        
            <LaneId>1</LaneId>        
            <AspectCode>Advisory20</AspectCode>      
        </LaneSelection>    
    </LaneSelections>  
</ProposalRequestMessage>  

I deserialize the message at the other end like so:

Queue = new System.Messaging.MessageQueue(queueName);
Queue.Formatter = new System.Messaging.XmlMessageFormatter(new Type[] { typeof(IvtmMessage) });
Queue.ReceiveCompleted += new System.Messaging.ReceiveCompletedEventHandler(Queue_ReceiveCompleted);
Queue.BeginReceive(new System.TimeSpan(0, 0, 0, 30));
...
System.Messaging.MessageQueue mq = (System.Messaging.MessageQueue)sender;
try
{    
     // End the asynchronous Receive operation.
     System.Messaging.Message m = mq.EndReceive(e.AsyncResult);

     IvtmMessage message = (IvtmMessage)m.Body;
     DecodeMessage(message);
}
catch (System.Messaging.MessageQueueException ex)
{
     string exception = ex.Message;
}
mq.BeginReceive();

return; 

Every member of the class is correctly deserialized except for the laneSelections element which, although it clearly has a value in the XML, evaluates to a null instances in the deserialized message.

In deseparation I tried adding a List to the class, populating it with the values 1-5 on construction. If this serialized correctly then it would show me that the problem is with the LaneSelection class, but if not then the issue would be with serializing a List. The List did not serialize correctly.

Does anyone know what’s going wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T22:09:37+00:00Added an answer on June 18, 2026 at 10:09 pm

    two things;

    1. There is “laneSelections” in the IvtmMessage declaration but the serialized XML is “LaneSelections” with a capital L. Xml serialization/deserialization is case sensitive and this is caught me out more than once
    2. Have you tried adding the following to the LaneSelections property of the IvtmMessage class as in the code below;

    Property definition;

     [XmlArray("LaneSelections"), XmlArrayElement("LaneSelection")]
     public List<LaneSelection> LaneSelections { get; set; }
    

    Without the proper Xml attributes on the properties and classes you’re leaving it up to the serializer to interpret how the properties/objects should be translated

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.