473,397 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Serialization and ISite

Hi,
I have inherited my class from System.Drawing.Printing.PrintDocument
and I wish to serialize this object using XmlSerializer. And I get
exception "There was an error reflecting type ...". If I look at
innerException it says: "Cannot serialize member
'System.ComponentModel.Component.Site' of type
'System.ComponentModel.ISite'.
OK it is problem to serialize all data so I'll implement my
Serialization. I implemented ISerializable interface, but the problem
is the same. Shouldn't implementation of ISerializable override
default serialization and allow me to serialize MyPrintDocument class?
And have you any suggestion how can I solve this problem?

Apr 4 '07 #1
4 11360
If you implement the ISerializable interface, this is not going to give
you the same semantics as using IXmlSerializer.

When using IXmlSerializer, it is going to serialize all public
properties. The problem with this is that if one of the properties exposes
an interface type, the Xml serialization engine doesn't know what the
appropriate implementation type should be (since it can be anything that
implements it) and won't know what to create when re-hydrating the object.

When you use the serialization engine, you are serializing the fields
that are in the object. Because of that, exposing interfaces on properties
doesn't matter, since the serialization engine is always going to dig into
the type and get the fields.

However, you have to make sure that all fields are of types that have
the Serializable attribute applied to them, which is the case here.

I would recommend using the Serialization framework (not the Xml
serialization framework) to serialize these types, and make sure that your
components site is either serializable, or don't serialize the reference to
the site in your custom ISerializable implementation.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<mi*****@gmail.comwrote in message
news:11**********************@y66g2000hsf.googlegr oups.com...
Hi,
I have inherited my class from System.Drawing.Printing.PrintDocument
and I wish to serialize this object using XmlSerializer. And I get
exception "There was an error reflecting type ...". If I look at
innerException it says: "Cannot serialize member
'System.ComponentModel.Component.Site' of type
'System.ComponentModel.ISite'.
OK it is problem to serialize all data so I'll implement my
Serialization. I implemented ISerializable interface, but the problem
is the same. Shouldn't implementation of ISerializable override
default serialization and allow me to serialize MyPrintDocument class?
And have you any suggestion how can I solve this problem?

Apr 4 '07 #2
or don't serialize the reference to
the site in your custom ISerializable implementation.
Yes, this is the thing that confuses me. I didn't serialize anything
else bat one strings (just for test)
[Serializable]
public class PrintLibDoc : System.Drawing.Printing.PrintDocument ,
ISerializable
{

public virtual void GetObjectData(SerializationInfo info,
StreamingContext context)
{
info.AddValue("DocName", this.DocumentName);
}
....
}

....
XmlSerializer serializer = new XmlSerializer(typeof(PrintLibDoc));
....
That's the reason why I implemented ISerializable. To prevent
serialization of members that are not serializable. PrintLibDoc shold
only serialize one string. I know that there are other ways to solve
this but this is confusing me.


On Apr 4, 5:09 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
If you implement the ISerializable interface, this is not going to give
you the same semantics as using IXmlSerializer.

When using IXmlSerializer, it is going to serialize all public
properties. The problem with this is that if one of the properties exposes
an interface type, the Xml serialization engine doesn't know what the
appropriate implementation type should be (since it can be anything that
implements it) and won't know what to create when re-hydrating the object.

When you use the serialization engine, you are serializing the fields
that are in the object. Because of that, exposing interfaces on properties
doesn't matter, since the serialization engine is always going to dig into
the type and get the fields.

However, you have to make sure that all fields are of types that have
the Serializable attribute applied to them, which is the case here.

I would recommend using the Serialization framework (not the Xml
serialization framework) to serialize these types, and make sure that your
components site is either serializable, or don't serialize the reference to
the site in your custom ISerializable implementation.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

<mija...@gmail.comwrote in message

news:11**********************@y66g2000hsf.googlegr oups.com...
Hi,
I have inherited my class from System.Drawing.Printing.PrintDocument
and I wish to serialize this object using XmlSerializer. And I get
exception "There was an error reflecting type ...". If I look at
innerException it says: "Cannot serialize member
'System.ComponentModel.Component.Site' of type
'System.ComponentModel.ISite'.
OK it is problem to serialize all data so I'll implement my
Serialization. I implemented ISerializable interface, but the problem
is the same. Shouldn't implementation of ISerializable override
default serialization and allow me to serialize MyPrintDocument class?
And have you any suggestion how can I solve this problem?- Hide quoted text -

- Show quoted text -

Apr 5 '07 #3
Well, that's the problem. Why are you using the XmlSerializer class
when the ISerializable interface is for Binary and Soap serialization?

If you want plain old xml for serialization, you need to implement the
IXmlSerializable interface, as THAT will give you control over the
serialization details.

If you are ok with Binary/SOAP serialization, then you can use the
BinaryFormatter or SoapFormatter classes to drive the serialization in the
System.Runtime.Serialization.Formatters.Binary and
System.Runtime.Serialization.Formatters.Soap namespaces, respectively.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<mi*****@gmail.comwrote in message
news:11*********************@d57g2000hsg.googlegro ups.com...
>
>or don't serialize the reference to
the site in your custom ISerializable implementation.

Yes, this is the thing that confuses me. I didn't serialize anything
else bat one strings (just for test)
[Serializable]
public class PrintLibDoc : System.Drawing.Printing.PrintDocument ,
ISerializable
{

public virtual void GetObjectData(SerializationInfo info,
StreamingContext context)
{
info.AddValue("DocName", this.DocumentName);
}
...
}

...
XmlSerializer serializer = new XmlSerializer(typeof(PrintLibDoc));
...
That's the reason why I implemented ISerializable. To prevent
serialization of members that are not serializable. PrintLibDoc shold
only serialize one string. I know that there are other ways to solve
this but this is confusing me.


On Apr 4, 5:09 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
> If you implement the ISerializable interface, this is not going to
give
you the same semantics as using IXmlSerializer.

When using IXmlSerializer, it is going to serialize all public
properties. The problem with this is that if one of the properties
exposes
an interface type, the Xml serialization engine doesn't know what the
appropriate implementation type should be (since it can be anything that
implements it) and won't know what to create when re-hydrating the
object.

When you use the serialization engine, you are serializing the fields
that are in the object. Because of that, exposing interfaces on
properties
doesn't matter, since the serialization engine is always going to dig
into
the type and get the fields.

However, you have to make sure that all fields are of types that have
the Serializable attribute applied to them, which is the case here.

I would recommend using the Serialization framework (not the Xml
serialization framework) to serialize these types, and make sure that
your
components site is either serializable, or don't serialize the reference
to
the site in your custom ISerializable implementation.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

<mija...@gmail.comwrote in message

news:11**********************@y66g2000hsf.googleg roups.com...
Hi,
I have inherited my class from System.Drawing.Printing.PrintDocument
and I wish to serialize this object using XmlSerializer. And I get
exception "There was an error reflecting type ...". If I look at
innerException it says: "Cannot serialize member
'System.ComponentModel.Component.Site' of type
'System.ComponentModel.ISite'.
OK it is problem to serialize all data so I'll implement my
Serialization. I implemented ISerializable interface, but the problem
is the same. Shouldn't implementation of ISerializable override
default serialization and allow me to serialize MyPrintDocument class?
And have you any suggestion how can I solve this problem?- Hide quoted
text -

- Show quoted text -


Apr 5 '07 #4
It's clear now.
Thanks a lot

On Apr 5, 6:16 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
Well, that's the problem. Why are you using the XmlSerializer class
when the ISerializable interface is for Binary and Soap serialization?

If you want plain old xml for serialization, you need to implement the
IXmlSerializable interface, as THAT will give you control over the
serialization details.

If you are ok with Binary/SOAP serialization, then you can use the
BinaryFormatter or SoapFormatter classes to drive the serialization in the
System.Runtime.Serialization.Formatters.Binary and
System.Runtime.Serialization.Formatters.Soap namespaces, respectively.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

<mija...@gmail.comwrote in message

news:11*********************@d57g2000hsg.googlegro ups.com...


or don't serialize the reference to
the site in your custom ISerializable implementation.
Yes, this is the thing that confuses me. I didn't serialize anything
else bat one strings (just for test)
[Serializable]
public class PrintLibDoc : System.Drawing.Printing.PrintDocument ,
ISerializable
{
public virtual void GetObjectData(SerializationInfo info,
StreamingContext context)
{
info.AddValue("DocName", this.DocumentName);
}
...
}
...
XmlSerializer serializer = new XmlSerializer(typeof(PrintLibDoc));
...
That's the reason why I implemented ISerializable. To prevent
serialization of members that are not serializable. PrintLibDoc shold
only serialize one string. I know that there are other ways to solve
this but this is confusing me.
On Apr 4, 5:09 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
If you implement the ISerializable interface, this is not going to
give
you the same semantics as using IXmlSerializer.
When using IXmlSerializer, it is going to serialize all public
properties. The problem with this is that if one of the properties
exposes
an interface type, the Xml serialization engine doesn't know what the
appropriate implementation type should be (since it can be anything that
implements it) and won't know what to create when re-hydrating the
object.
When you use the serialization engine, you are serializing the fields
that are in the object. Because of that, exposing interfaces on
properties
doesn't matter, since the serialization engine is always going to dig
into
the type and get the fields.
However, you have to make sure that all fields are of types that have
the Serializable attribute applied to them, which is the case here.
I would recommend using the Serialization framework (not the Xml
serialization framework) to serialize these types, and make sure that
your
components site is either serializable, or don't serialize the reference
to
the site in your custom ISerializable implementation.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
<mija...@gmail.comwrote in message
>news:11**********************@y66g2000hsf.googleg roups.com...
Hi,
I have inherited my class from System.Drawing.Printing.PrintDocument
and I wish to serialize this object using XmlSerializer. And I get
exception "There was an error reflecting type ...". If I look at
innerException it says: "Cannot serialize member
'System.ComponentModel.Component.Site' of type
'System.ComponentModel.ISite'.
OK it is problem to serialize all data so I'll implement my
Serialization. I implemented ISerializable interface, but the problem
is the same. Shouldn't implementation of ISerializable override
default serialization and allow me to serialize MyPrintDocument class?
And have you any suggestion how can I solve this problem?- Hide quoted
text -
- Show quoted text -- Hide quoted text -

- Show quoted text -

Apr 6 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined...
3
by: Aaron Clamage | last post by:
Hi, I'm not sure that if this is the right forum, but any help would be greatly appreciated. I am porting some java serialization code to c# and I can't figure out the correct way to do it. ...
3
by: Alexander | last post by:
When i store rule on PC with .NET.SP1 i cant restore them from PC without SP1. An i get this Error: System.Runtime.Serialization.SerializationException: Possible Version mismatch. Type...
0
by: Dale Preston | last post by:
I have the following three classes: MyControl : System.Web.UI.WebControls.WebControl MyChildObject and MyChildCollection : CollectionBase MyControl has a public property, ChildCollection, of...
2
by: RJ | last post by:
I've been trying to find documentation that explains limitation of possible types that a webmethod can return. I realize xml serialization must take place to return the specified type. Must the...
0
by: Kiran A K | last post by:
Hi, When I try to return an object of type "System.Diagnostics.PerformanceCounter" from a web method i got the following error: Cannot serialize member System.ComponentModel.Component.Site of...
0
by: bharathreddy | last post by:
Before going to that i want to say few thing on serialization : Serialization is the process of converting an object into a form that can be readily transported. For example, you can serialize an...
1
by: kikisan | last post by:
I am developing a windows service which utilizes the following classes: interface IPersistable; abstract class PersistableObject : IPersistable;
2
by: mkvenkit.vc | last post by:
Hello, I hope this is the right place to post a question on Boost. If not, please let me know where I can post this message and I will do so. I am having a strange problem with std::string as...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.