There was an error generating the XML document.
Hi All,
I have a DLL contains two classes, first one which is to be serialized
and other one is a UserControl class have code to serialize as below:-
class XYZ: System.Windows.Forms.UserControl
{
public XYZ()
{
string _preferencesFile = "c:\test_xml.xml";
XMLTest.PrefData _preferences = new XMLTest.PrefData();
XmlTextWriter writer = new XmlTextWriter(_preferencesFile,
System.Text.Encoding.UTF8);
XmlSerializer serializer = null ;
writer.Formatting = Formatting.Indented;
serializer = new XmlSerializer(typeof(XMLTest.PrefData));
//serializer.Serialize(writer,preferences);
serializer.Serialize(writer,(XMLTest.PrefData)_pre ferences);
writer.Flush();
writer.Close();
}
.......
Now If I create the object of XYZ like below
System.Windows.Forms.UserControl xyz = new XYZ();
the code written in the constructor works fine.
But I load this usercontrol thru reflection then it throw the error
"There was an error generating the XML document. " and inner exception
as "Specified cast is not valid";
Assembly asmAssemblyContainingForm = Assembly.LoadFrom("XMLTest.dll");
Type typeToLoad = asmAssemblyContainingForm.GetType("XMLTest.XYZ");
System.Windows.Forms.UserControl allocationInstance =
(System.Windows.Forms.UserControl)Activator.Create Instance(typeToLoad);
Please let me know if there are thoughts to solve this problem.
Thanks,
Utkarsh
|