473,327 Members | 2,074 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,327 software developers and data experts.

Problem to serialize a property that return an interface


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 11 '05 #1
1 5382
The XmlSerializer has to have an instantiated object during serialization.
For an interface, however, it would not know what type to instantiate.
Working around this limitation, you can use an abstract base class to
express the semantics of your interface. For example:

public abstract class IWizard
{
public abstract int x
{
get;
set;
}
}
[Serializable]
public class Geometry
{
private IWizard _wizard;
public IWizard Wizard
{
get { return _wizard ;}
set { _wizard = value;}
}
}

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 11 '05 #2

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

Similar topics

0
by: Rhy Mednick | last post by:
I have a series of simple controls that I created to make some aspects of Tablet PC programming a little easier. The "Tablet PC" aspects of the controls are irrelevant to the problem I'm having,...
3
by: Julia | last post by:
Hi, I have an two classes derived from ICommand interface for example SubscribeCommand,and RetryCommand i want to do the following ICommand command1=new SubscribeCommand() ICommand...
1
by: nate axtell | last post by:
I have a custom class with a Private DataTable member and a Public Property that returns this DataTable in its Get call. Is the DataTable that is returned from the Property's Get a reference to...
2
by: ABC | last post by:
Which function or property return the current page URL?
5
by: Sam | last post by:
Hi All I have couple of question regarding property of a class and structures. **** ---- Here is my class and structure ---- ***** 1. Public Structure MyPoint 2. Dim p As Point 3. ...
0
by: haynes george | last post by:
hi .. I was reading the tutorial "Extending and Embedding the python interpreter" available with python .. http://www.python.org/doc/2.2.3/ext/ext.html As per given in the tutorial i...
7
by: none | last post by:
I'm trying to implement a simple repeateable property mechansism so I don't have to write accessors for every single instance variable I have. ------------ classMyObject: def __init__ (self):...
6
by: David Hearn | last post by:
I have a property in a user control that I am setting: Private strPageName as String Public Property PageName() as String Get Return strPageName End Get Set(byVal Value as String)...
2
by: Cristiano de Pádua Milagres Oliveira | last post by:
What do I to declare the header of a Property in an Interface, and should this property return a generic Enum? Example: public interface IMetric { Enum Unit { get;} } public class...
3
by: Joe | last post by:
Hi I have a propertygrid that I allow the user to pick a system.color and I want to save to a file to load later onto the propertygrid. String and bool values work but I am unable to save...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.