472,331 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,331 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 11173
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...
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#...
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: ...
0
by: Dale Preston | last post by:
I have the following three classes: MyControl : System.Web.UI.WebControls.WebControl MyChildObject and MyChildCollection : CollectionBase ...
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...
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...
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...
1
by: kikisan | last post by:
I am developing a windows service which utilizes the following classes: interface IPersistable; abstract class PersistableObject :...
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. ...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.