Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old March 8th, 2006, 06:55 PM
utkarsh
Guest
 
Posts: n/a
Default 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

 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles