XmlSerializer Error

Aug 29, 2014 at 9:05 AM
Hello,
I'm new to ediFabric. I wan't make an Edi Message from a .net object.
My test code is here :
        Dim ediObject = New INTERCHANGE()
        'construct the object…
        ediObject.GROUPS = New List(Of GROUP)
        Dim lcGrp As GROUP = New GROUP
        lcGrp.MESSAGES = New List(Of EdiFabric.Framework.Entities.Message)
        Dim lcInVoic As New M_INVOIC

        Dim lcMess As New EdiFabric.Framework.Entities.Message(lcInVoic)
        lcGrp.MESSAGES.Add(lcMess)
        ediObject.GROUPS.Add(lcGrp)
   
But on the message object creation, (New EdiFabric.Framework.Entities.Message(lcInVoic)), I get the following error : "type EdiFabric.Definitions.Edifact_D99B_INVOIC.M_INVOIC not expected. use xmlinclude or soapinclude".
The error is comming here :
  public static XElement Serialize<T>(T instance, string nameSpace)
        {
            var serializer = new XmlSerializer(typeof(T), nameSpace);
            using (var ms = new MemoryStream())
            {
                __serializer.Serialize(ms, instance);__
                ms.Position = 0;
                return XElement.Load(ms, LoadOptions.PreserveWhitespace);
            }
        }
Do you know what I'm doing wrong?
Sorry for my poor english and thank you for help me !
Aug 29, 2014 at 2:54 PM
Re,
the problem is in the Serialize Method... I don't know the cause but the T type is see as a generic object.
So, the serialize Method of the xmlSerializer object don't know the type to serialize.
I solve the problem with this modified method
 public static XElement Serialize(object instance, string nameSpace)
        {
            Debug.WriteLine(instance.GetType().ToString());

            var serializer = new XmlSerializer(instance.GetType(), nameSpace);
            using (var ms = new MemoryStream())
            {
                serializer.Serialize(ms, instance);
                ms.Position = 0;
                return XElement.Load(ms, LoadOptions.PreserveWhitespace);
            }
        }
I think my solution is not very good and I don't know the repercussions it may caused...
I think the probleme is present since the 4.1 version and the 4.0 version seem's to be ok.
For information, the sample application doesn't work on the 4.1 version in my environment but the unitTest are ok.
I don't know if it's related.

Thank you a lot for your project and sorry for my english!
Coordinator
Oct 8, 2014 at 9:00 PM
Hi,

You are correct - there was a reported issue on this and the solution is exactly the one you've come up with.

I will include this in the next release and then will close the issue, it's just checked in for now.

Thank you for reporting this.

Don