469,648 Members | 1,124 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,648 developers. It's quick & easy.

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

Mar 8 '06 #1
0 1844

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Alejandro Penate-Diaz | last post: by
3 posts views Thread by Raed Sawalha | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.