364,085 Members | 5185 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

Problem to serialize a property that return an interface

Pol Bawin
P: n/a
Pol Bawin

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
Share this Question
Share on Google+
1 Reply


MSFT
P: n/a
MSFT
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

Post your reply

Help answer this question



Didn't find the answer to your .NET Framework question?

You can also browse similar questions: .NET Framework