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

Serializing an object that has members of type interface

axr
Having trouble with Serilization of objects that contain members which are of
type Interface

eg
public class SomeClass
{

ISomeInterface1 itf1;
ClassType1 ct1;
ISomeInterface2 itf2;
/**
// code
**/
}
itf1 and itf2 are instances of classes that implement the respective
interfaces.
The ClassType in turn may have other members that are of type interfaces.
While serializing this barfs with error "Cannot serialize xx because its an
interface."
Any pointers on how to serialize this kind of an object?? (without getting
rid of the interface members)
Nov 23 '05 #1
3 6845
Did you ever get a reply to this question?

"axr" wrote:
Having trouble with Serilization of objects that contain members which are of
type Interface

eg
public class SomeClass
{

ISomeInterface1 itf1;
ClassType1 ct1;
ISomeInterface2 itf2;
/**
// code
**/
}
itf1 and itf2 are instances of classes that implement the respective
interfaces.
The ClassType in turn may have other members that are of type interfaces.
While serializing this barfs with error "Cannot serialize xx because its an
interface."
Any pointers on how to serialize this kind of an object?? (without getting
rid of the interface members)

Nov 23 '05 #2
DC
An interface collects only methods.
Since the XmlSerializer serializes only public fields and properties, the
XmlSerializer necessarily does not "do" interfaces.

Suppose your custom type has a public property that is ISomeInterface, if
the serializer peeked into that interface it would find no public fields or
methods; essentially there is no data attached to the interface. Therefore
it makes sense for nothing to be serialized there.

By serializing interfaces, what are you hoping to accomplish? what is your
goal?

If you want to serialize the state of an object, consider the binary
serializer.

-D
"Jack" <Ja**@discussions.microsoft.com> wrote in message
news:8E**********************************@microsof t.com...
Did you ever get a reply to this question?

"axr" wrote:
Having trouble with Serilization of objects that contain members which
are of
type Interface

eg
public class SomeClass
{

ISomeInterface1 itf1;
ClassType1 ct1;
ISomeInterface2 itf2;
/**
// code
**/
}
itf1 and itf2 are instances of classes that implement the respective
interfaces.
The ClassType in turn may have other members that are of type interfaces.
While serializing this barfs with error "Cannot serialize xx because its
an
interface."
Any pointers on how to serialize this kind of an object?? (without
getting
rid of the interface members)

Nov 23 '05 #3
"DC" wrote:
An interface collects only methods.
Since the XmlSerializer serializes only public fields and properties, the
XmlSerializer necessarily does not "do" interfaces.

Suppose your custom type has a public property that is ISomeInterface, if
the serializer peeked into that interface it would find no public fields or
methods; essentially there is no data attached to the interface. Therefore
it makes sense for nothing to be serialized there.

By serializing interfaces, what are you hoping to accomplish? what is your
goal?


My IFoo interface, that contains properties, is implemented by a series of
classes, FooImpl1 and FooImpl2. I've created a collection class FooCollection
(implementing ICollection & more) that contains IFoo objects. I want to
serialize the objects in the collection.

My workaround is to convert IFoo into an abstract/viirtual base class, Foo
which is then extended by FooImpl1 and FooImpl2, however, this doesn't work
when a class needs to implement multiple interfaces.
Nov 23 '05 #4

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

Similar topics

1
by: mattoc | last post by:
Happy new year to all. I have a strange error that I've been trying for a while now to fathom.. Basically I have a hierarchy of state classes that I need to serialize to XML. Some of them can...
2
by: Tobias Zimmergren | last post by:
Hi, just wondering what serializing really is, and howto use it? Thanks. Tobias __________________________________________________________________ Tobias ICQ#: 55986339 Current ICQ status: +...
1
by: Akshay Kumar | last post by:
I have a collection class and in order to make it type safe etc , I only add and retrive members of Interface types. But during XMLSerialization I get errors. Is there any workaround ? ...
5
by: Kurt Lange | last post by:
How to I dereference a pointer to an object. I say dereference, because I don't now how to better explain this.... function firstFunction(byval obj as class1) as class1 dim returnVal as...
6
by: Rick | last post by:
Hi, Can anyone explain to me why the below fails to compile - seeing otherA->f(); as a call to a inaccessible function, while otherB->f(); is ok? It seems you can happily access protected...
2
by: she_prog | last post by:
I have a class derived from UserControl. I need to serialize an object of this class, but only some properties of it, as not all properties are serializable (some of the properties coming from...
3
by: wildThought | last post by:
If I have an object that contains a generic dictionary inside of it, how do I get access to its properties such as count?
0
by: Joris van Lier | last post by:
Hi, I'm looking for advice on mapping between different XML Schamata. The C# (2.0) project I'm currently working on needs to send custom business entities to multiple webservices, each accepting...
23
by: tonytech08 | last post by:
What I like about the C++ object model: that the data portion of the class IS the object (dereferencing an object gets you the data of a POD object). What I don't like about the C++ object...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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,...

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.