Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / .NET SDK / October 2004

Tip: Looking for answers? Try searching our database.

Problem retrieving type for XML Serialization

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lee - 29 Oct 2004 15:14 GMT
I am having a problem using XML Serialization.

I have a class that serializes an object and saves it to disk, (sort of a
page file system for a web app).

You pass in the object, and the serialization method to use and it will
serialize it to disk for later retrievel.

The following scenarios work great:

1. Serializing anything with Binary Serialization
2. Serializing any type in the System namespace with XML Serialization

The following scenario is where I am having difficulty:

3. Serializing any type not in the System namespace (ie System.Data.Dataset)

The problem actually occurs in the deserialization when I am trying to
retrieve the type of the object to pass it to the constructor of the
XmlSerializer object.

Here is the code that is giving me trouble:

   Type oType = Type.GetType(oNode.Attributes["type"].InnerText,true, true);

For example, when I am trying to deserialize a Dataset object, the InnerText
property of this node is set to "System.Data.Dataset", and I receive the
following exception at that line of code:

System.TypeLoadException : Could not load type System.Data.DataSet from
assembly PageFileManager

(PageFileManager is the calling class)

So my two questions are:

1. Am I missing a step here where I need to use reflection to load some
assembly.

or

2. Is there a way  to deserialize XML without specifying the type in the
constructor of the XmlSerializer object?

Thanks in advance,

Lee
Lee - 29 Oct 2004 15:33 GMT
I figured this out, in case anyone else has this problem here is the key:

Originally I was doing this to save the type information:

  oNode.Attributes["type"].InnerString = oObjectType.ToString();

So in the case of System.Data.Dataset, It would save "System.Data.Dataset".

I changed the above line to this:

  oNode.Attributes["type"].InnerString = oObjectType.AssemblyQualifiedName;

And this would save:

"System.Data.DataSet, System.Data, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089"

Then the subsequent call to Type.GetType() was able to load the type from
this fully qualified name.

Maybe this was obvious to other people, but it wasn't to me. However after
thinking about it, it wouldn't make sense for the CLR to keep track of all of
the System dlls and their types.

Lee

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.