I have an xml file containing some stuff.
I use xsd to generate a schema and again to create classes from the schemas.
added using System, System.IO;
added [Serializable] to all classes
added namespace ROC
added deserialize() method as follows to AWLR2 class:
public AWLR2 deserialize(string xmlString)
{
AWLR2 awlr2;
try
{
StringReader sr = new StringReader(xmlString);
XmlSerializer ser = new XmlSerializer(this.GetType());
awlr2=(AWLR2)ser.Deserialize(sr);
}
catch(Exception ex)
{
System.Diagnostics.EventLog.WriteEntry("BizTalk Redemptions",
ex.ToString());
throw ex;
}
return awlr2;
}
I attempt to deserialize from a string using the same xml with escaped
quotes to prove it all works and we start with the problems.
The escaped text is as follows:
<AWLR2 xmlns=\"http://Schemas_cares.AWLR2\"><D-1A-1 xmlns=\"\"><LL:LincList
xmlns:LL=\"http://Schemas_cares.LincList\"><Row><Col
Index=\"1\">00200170601</Col><Col Index=\"2\">002001706</Col><Col
Index=\"3\"></Col></Row><Row><Col Index=\"1\">00200170601</Col><Col
Index=\"2\">014628102</Col><Col Index=\"3\"></Col></Row><Row><Col
Index=\"1\">03639200702</Col><Col Index=\"2\">026269507</Col><Col
Index=\"3\"></Col></Row><Row><Col Index=\"1\">03306230708</Col><Col
Index=\"2\">026880902</Col><Col Index=\"3\"></Col></Row><Row><Col
Index=\"1\">03306230708</Col><Col Index=\"2\">033062307</Col><Col
Index=\"3\"></Col></Row><Row><Col Index=\"1\">03639200702</Col><Col
Index=\"2\">036502207</Col><Col Index=\"3\"></Col></Row><Row><Col
Index=\"1\">03850780601</Col><Col Index=\"2\">038507806</Col><Col
Index=\"3\"></Col></Row><Row><Col Index=\"1\">03850780601</Col><Col
Index=\"2\">038588908</Col><Col
Index=\"3\"></Col></Row></LL:LincList></D-1A-1></AWLR2>
I call the deserialize() method and it does not throw any exceptions.
I try to reference objects that should have been created on deserialization
and whilst AWLR2 exists, the objects that AWLR2 should have, do not.
My unit test reports the text passed correctly, and the existence of the
awlr2 object.
Console.WriteLine("awlr2 exists: " + (awlr2 != null).ToString()); //OK
but not
Console.WriteLine("Items exists: " + (awlr2.Items != null).ToString());
This throws NullReferenceException.
Any ideas please. I have checked all the attributes created by xsd on the
properties of the classes and they seem fine. Serialization is not a
problem. Just deserialization.
cheers
PeterW