I am using XMLSerialization to pass data from a client based Win7 application to our server (Server 2008 R2) via a Pipe communication process. I have been brought into this project to finish the previous developer's efforts who abandoned it ... therefore I am presently trying to fix the C# code in VS2010 that doesn't work.
The problem is that I cannot obtain full serialization of the resulting output from the following method which is in "public partial class Test". We have a table defined in the MS Compact Server database (named "Test") which matches each item below and has a FK to the "Channel" table, based on matching TestID's in both tables. EntityCollection is based on its relationship to the "Channel" table:
public Test(Guid TestID, String TestName, String TestRemarks, String ScriptPath,
EntityCollection<Channel> TChannels)
{
ID = TestID;
Name = TestName;
Remarks = TestRemarks;
Path = ScriptPath;
Channels = TChannels;
}
Here is a sample of how it is used in the execution of the method:
Test T = new Test(NewID, "Test1", "Test_120912-1729",
"C:\\Temp\\TestScript_16.txt", TChannels);
Here is the result of the serialization process:
<DataCore xsi:type="Test">
<ID>bc6a8ef7-c31f-404d-8108-86219d45be63</ID>
<Name>Test1</Name>
<Remarks>Test_120912-1729</Remarks>
<Path>C:\Temp\TestScript_16.txt</Path>
</DataCore>
The first four parameters serialize fine, but the last one (the EntityCollection) is failing to do so. However, if I try to serialize "TChannels" by itself (outside the "Test" function) the serialization of each Test Channel works perfectly. I don't fully understand the limitations/requirements for utilizing XMLserialization to solve this problem. Why am I unable to serialize the EntityCollection< > from within the function?
Thanks for your assistance!
I finally found a solution to the above problem. While the many suggestions were appreciated, none of them provided a solution to my inability to XmlSerialize a child EntityCollection. I dug deeper and looked into the ADO.NET Framework and found within the auto generated code in my database Model.Designer.cs file, an [XmlIgnoreAttribute()] near the beginning of Navigation Properties in my Test (EdmEntityTypeAttribute).
I simply removed the [XmlIgnoreAttribute()] line completely and now all the child objects of "Channels" from the EntityCollection<> are Serialized properly. I hope this can help others who are also unable to Serialize child objects.
Thanks @Dave R.