473,770 Members | 3,710 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem to serialize a interface in Xml


A class has a private field of type IWizard (An interface) and a public
property to access it.
When I try to serialize the Geometry class in XML, i have an error but it
works in Binary

Can you help me

[Serializable]
public class Geometry
{
....
private IWizard _wizard;
public IWizard Wizard
{
get { return _wizard ;}
set { _wizard = value;}
}
}
Nov 15 '05 #1
3 2307

Hi Pol,

I think that this has something to do with the one of the follwoing:
1. the XmlSerializer has to able able to instantiate an object during
deserialization . For an interface, however, it would not know what type to
instantiate.

2. serializing an interface only may only serialize the part of the class
that implements the interface, but not public fields that are not part of
the interface. When deserializing the instance would not have all it's
public fields in the state it was in when you passed the interface to the
Serialize method.

To work around this problem, you can You can use an abstract base class to
express the semantics of your interface.

Hope this helps,

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Pol Bawin" <pb@rtech.be>
| Subject: Problem to serialize a interface in Xml
| Date: Thu, 2 Oct 2003 15:32:35 +0200
| Lines: 21
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <#R************ **@TK2MSFTNGP12 .phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
| NNTP-Posting-Host: 194.78.114.66
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP12.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1885 49
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
|
|
| A class has a private field of type IWizard (An interface) and a public
| property to access it.
| When I try to serialize the Geometry class in XML, i have an error but it
| works in Binary
|
| Can you help me
|
| [Serializable]
| public class Geometry
| {
| ....
| private IWizard _wizard;
| public IWizard Wizard
| {
| get { return _wizard ;}
| set { _wizard = value;}
| }
| }
|
|
|

Nov 15 '05 #2
Ok but in this case, an attribute (xmlElement(... ) or xmlType(...) ) must be
added. Ok for a static structure but I my case these Type can be added
dynamicly.

"Jeffrey Tan[MSFT]" <v-*****@online.mi crosoft.com> a écrit dans le message
de news: Qb************* *@cpmsftngxa06. phx.gbl...

Hi Pol,

I think that this has something to do with the one of the follwoing:
1. the XmlSerializer has to able able to instantiate an object during
deserialization . For an interface, however, it would not know what type to
instantiate.

2. serializing an interface only may only serialize the part of the class
that implements the interface, but not public fields that are not part of
the interface. When deserializing the instance would not have all it's
public fields in the state it was in when you passed the interface to the
Serialize method.

To work around this problem, you can You can use an abstract base class to express the semantics of your interface.

Hope this helps,

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Pol Bawin" <pb@rtech.be>
| Subject: Problem to serialize a interface in Xml
| Date: Thu, 2 Oct 2003 15:32:35 +0200
| Lines: 21
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <#R************ **@TK2MSFTNGP12 .phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
| NNTP-Posting-Host: 194.78.114.66
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP12.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1885 49 | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
|
|
| A class has a private field of type IWizard (An interface) and a public | property to access it.
| When I try to serialize the Geometry class in XML, i have an error but it | works in Binary
|
| Can you help me
|
| [Serializable]
| public class Geometry
| {
| ....
| private IWizard _wizard;
| public IWizard Wizard
| {
| get { return _wizard ;}
| set { _wizard = value;}
| }
| }
|
|
|

Nov 15 '05 #3

Hi Pol,

Thanks for your reply.
Can you tell me what does your " these Type can be added dynamicly" mean?

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Pol Bawin" <pb@rtech.be>
| Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
| References: <#R************ **@TK2MSFTNGP12 .phx.gbl>
<Qb************ **@cpmsftngxa06 .phx.gbl>
| Subject: Re: Problem to serialize a interface in Xml
| Date: Fri, 3 Oct 2003 17:05:55 +0200
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Lines: 76
| Message-ID: <3f************ ***********@rea der2.news.skyne t.be>
| Organization: -= Belgacom Usenet Service =-
| NNTP-Posting-Host: 194.78.114.66
| X-Trace: 1065193555 reader2.news.sk ynet.be 10695 194.78.114.66:4 5476
| X-Complaints-To: us**********@sk ynet.be
| Path:
cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!new sfeed00.sul.t-online.de!t-onlin
e.de!skynet.be! skynet.be!louie !tlk!not-for-mail
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1887 72
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
|
| Ok but in this case, an attribute (xmlElement(... ) or xmlType(...) ) must
be
| added. Ok for a static structure but I my case these Type can be added
| dynamicly.
|
| "Jeffrey Tan[MSFT]" <v-*****@online.mi crosoft.com> a écrit dans le message
| de news: Qb************* *@cpmsftngxa06. phx.gbl...
| >
| > Hi Pol,
| >
| > I think that this has something to do with the one of the follwoing:
| > 1. the XmlSerializer has to able able to instantiate an object during
| > deserialization . For an interface, however, it would not know what type
to
| > instantiate.
| >
| > 2. serializing an interface only may only serialize the part of the
class
| > that implements the interface, but not public fields that are not part
of
| > the interface. When deserializing the instance would not have all it's
| > public fields in the state it was in when you passed the interface to
the
| > Serialize method.
| >
| > To work around this problem, you can You can use an abstract base class
| to
| > express the semantics of your interface.
| >
| > Hope this helps,
| >
| > Best regards,
| > Jeffrey Tan
| > Microsoft Online Partner Support
| > Get Secure! - www.microsoft.com/security
| > This posting is provided "as is" with no warranties and confers no
rights.
| >
| > --------------------
| > | From: "Pol Bawin" <pb@rtech.be>
| > | Subject: Problem to serialize a interface in Xml
| > | Date: Thu, 2 Oct 2003 15:32:35 +0200
| > | Lines: 21
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| > | Message-ID: <#R************ **@TK2MSFTNGP12 .phx.gbl>
| > | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
| > | NNTP-Posting-Host: 194.78.114.66
| > | Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP12.phx.g bl
| > | Xref: cpmsftngxa06.ph x.gbl
| microsoft.publi c.dotnet.langua ges.csharp:1885 49
| > | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
| > |
| > |
| > | A class has a private field of type IWizard (An interface) and a
| public
| > | property to access it.
| > | When I try to serialize the Geometry class in XML, i have an error but
| it
| > | works in Binary
| > |
| > | Can you help me
| > |
| > | [Serializable]
| > | public class Geometry
| > | {
| > | ....
| > | private IWizard _wizard;
| > | public IWizard Wizard
| > | {
| > | get { return _wizard ;}
| > | set { _wizard = value;}
| > | }
| > | }
| > |
| > |
| > |
| >
|
|
|

Nov 15 '05 #4

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

Similar topics

5
5024
by: Lucas | last post by:
Well, here's the situation.. It's pretty simple; just that I can't get it to work. I have 2 Executables.. The first one is called CSharp.exe which is a simple WinForm App. I have a single button on the form which does the following OnClick. // CSharp.cs private void button1_Click(object sender, System.EventArgs e)
1
13642
by: n_o_s_p_a__m | last post by:
My web service has a webmethod whose return type is declared as an interface type, for example: public IBusinessProcess GetBusinessProcess() {} which generates the lovely error: Cannot serialize interface IBusinessProcess
2
22114
by: | last post by:
Is there anybody who can help me to serialize a control like buttons, textbox, and each other control?I don't want to inherit from some of those.I try with SoapFormatter but it tell it can't serialize the control because it doesn't have the attribute. After I try with a XmlSerializer but it tells that it can't serialize it.Anyone has some idea?
2
1635
by: Avin Patel | last post by:
Hi I have converted the code from Java to C#, using .net tool The Base Class implementes ISerializable interface. Which makes me implement this interface in all inherited class, In order to get the serilization work I can't use just attribute, as it doesn't support versioning Is there any work around? So inherited class don't implement ISerialzable interface, but still I can serialize inherited class Is there any other way to...
2
2179
by: Andrew G. J. Fung | last post by:
Can anyone please explain to me why the code below throws an exception? It seems to occur when deserializing an instance of a subclass, whose base class holds a struct, where said struct holds an instance to a reference type (but not System.String). The commented out code are lines that when enabled (and any conflicting lines disabled) stop the exception from being thrown. Thanks kindly, Andrew.
2
2358
by: ofer | last post by:
Hi, I am working with the beta version of the new .net framework (Whidbey) and I encountered a problem with serialization that did'nt exist in the .net 2003 the situation is like this : I have a class that inherits from dataset, and I want to serialize it , so I created a serialization constructor that forwards the call to the base class (the dataset) serialization constructor, normally, for this action to succeed I am supposed to put...
6
2638
by: Joe | last post by:
Hello All, I want to serialize a hashtable to a database table to persist its values between postbacks. The client requires that I not use ViewState, hence the database. The samples in MSDN show how to serialize a class that implements the ICollection interface to a file. Does anyone know how to serialize to a database table and conversely de-serialize from the table?
1
5554
by: J. Askey | last post by:
I am implementing a web service and thought it may be a good idea to return a more complex class (which I have called 'ServiceResponse') in order to wrap the original return value along with two other properties... bool error; string lastError; My whole class looks like this... using System;
3
10263
by: Julie | last post by:
Here's the scenario (public attributes, etc. omitted for brevity): class Base { } class Derived : Base { }
0
9432
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10008
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7420
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3974
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3578
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2822
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.