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 / April 2006

Tip: Looking for answers? Try searching our database.

Question regarding serialization and System.Uri

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rob Millman - 05 Apr 2006 15:17 GMT
I am trying to serialize an instance of the Uri class.  The class implements
the ISerializable interface but when I try to use an XMLSerializer to
serialize it, I get an exception that the object cannot be serialized because
it does not implement a default constructor (no parameters).  Is this a "bug"
in the framework or am I doing something wrong?

Robert Millman
"Peter Huang" [MSFT] - 06 Apr 2006 04:55 GMT
Hi Robert,

Based on my research, this is be design. Not all the .NET class can be XML
serialized.
XmlSerializerPreCompiler
Here is tool from Chris Sells which can check if certian class can be  XML
serialized.
http://www.sellsbrothers.com/tools/
This is for .NET 1.1.

If you do need to serialize it, I think you may need to Write your own
class to stored the URI information.
Commonly I think a string is OK. So that we can serialize it.

Thanks for your understanding!

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Rob Millman - 06 Apr 2006 20:14 GMT
I'm a bit confused.  The class implements the ISerializable interface.  If
the class cannot be serialized by design, why does it implement the
interface?  I ask these questions for two reasons, 1) to understand the .NET
framework classes better and 2) to better understand how I should design my
classes.

Thanks for YOUR understanding.

Robert Millman

> Hi Robert,
>
[quoted text clipped - 22 lines]
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
"Peter Huang" [MSFT] - 07 Apr 2006 03:43 GMT
Hi Robert,

I am sorry if I have any confusion.

If a class can be XML serialized did not depend on if the customer has
implement the ISerializable.
If we look into the MSDN, we will find the related class about the
ISerializable is under the namespace System.Runtime.Serialization.

While the XMLSerializer is under the namespace System.Xml.Serialization.
They are using different approach to do the serialization. e.g. In
XMLSerializer, it will generated dynamic assembly, but the
System.Runtime.Serialization will not.

Here are some link about Run-time Serialization for your reference.
Run-time Serialization
http://msdn.microsoft.com/msdnmag/issues/02/04/net/
Run-time Serialization, Part 2
http://msdn.microsoft.com/msdnmag/issues/02/07/net/
Run-time Serialization, Part 3  
http://msdn.microsoft.com/msdnmag/issues/02/09/net/

So far we did not have a official document about which class can be xml
serialized.
Commonly a very simple class can be XML serialized.
So we have a tool as I post before to check the class you are developing.

Introducing XML Serialization  
http://msdn2.microsoft.com/en-us/library/182eeyhh.aspx

If you still have any concern, please feel free to post here.

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Rate this thread:







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.