473,396 Members | 1,895 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,396 software developers and data experts.

Serialize and deserialize against interface??


oop Q:

If I serialize an interface array, then later deserialize it, do I need the
original
assembly to deserialize it???

Eg:
// Inside of "globaly assembly"
public interface Ianimal
{
string myColor
{ get;}
}

// "Dog Assembly" Inside of dynamicaly loaded assembly.
// Knows only "global Assembly"
public class dog: Ianimal
{
string myColor
{
get{return "black";}
}
}

// my main Assembly where the "magic" happens.
//Initialy only knows the "global assembly"
pubilc class myMainClass
{
Type AnimalType;

void DynamiclyLoadAssembly(string assemblyFileName)
{ //ommitted,but this is where AnimalType is defined}

private Ianimal[] myAnimals;

void SomeFunction(int x)
{
Ianimal[x] = (Ianimal) (new AnimalType());
}

private SerializeAnimals(Ianimals[] myAnimals )
{//ommitted}

private DeserializeMyAnimals()
{
//Q: If the next time I run the app, and I dont load the "Dog Assembly",
// will this fail?????????????????????????????
}
}
Thanks in advance.
Jan 12 '07 #1
2 3127
Hi,

No, that will not work. The underlying Type is required, and if the
formatter cannot find it then it will fail.

An interface requires an implementation and so cannot be constructed - it's
the concrete type that must be constructed. The full type name of the
concrete implementation that was serialized is stored in the serialized
object graph and the formatter will attempt to use this information to load
the Type meta data at runtime. Obviously, if your assembly is not
referencing the type's assembly, then the formatter will not be able to
resolve the Type and the operation will fail.

--
Dave Sexton
http://davesexton.com/blog

"TheMadHatter" <Th**********@discussions.microsoft.comwrote in message
news:15**********************************@microsof t.com...
>
oop Q:

If I serialize an interface array, then later deserialize it, do I need
the
original
assembly to deserialize it???

Eg:
// Inside of "globaly assembly"
public interface Ianimal
{
string myColor
{ get;}
}

// "Dog Assembly" Inside of dynamicaly loaded assembly.
// Knows only "global Assembly"
public class dog: Ianimal
{
string myColor
{
get{return "black";}
}
}

// my main Assembly where the "magic" happens.
//Initialy only knows the "global assembly"
pubilc class myMainClass
{
Type AnimalType;

void DynamiclyLoadAssembly(string assemblyFileName)
{ //ommitted,but this is where AnimalType is defined}

private Ianimal[] myAnimals;

void SomeFunction(int x)
{
Ianimal[x] = (Ianimal) (new AnimalType());
}

private SerializeAnimals(Ianimals[] myAnimals )
{//ommitted}

private DeserializeMyAnimals()
{
//Q: If the next time I run the app, and I dont load the "Dog
Assembly",
// will this fail?????????????????????????????
}
}
Thanks in advance.

Jan 12 '07 #2
I've seen this confusion before with remoting and serialization. When
you remote a Server Activated Object you don't need access to the
concrete implementation any interface implemented on the object will
suffice and in fact is the prefered way of going about it. So some
people make a leap of faith and assume that this will work with
serialization as well.

No idea if that's where you were coming from, but thought it added a
tincy tiny bit of value :)

TheMadHatter wrote:
oop Q:

If I serialize an interface array, then later deserialize it, do I need the
original
assembly to deserialize it???

Eg:
// Inside of "globaly assembly"
public interface Ianimal
{
string myColor
{ get;}
}

// "Dog Assembly" Inside of dynamicaly loaded assembly.
// Knows only "global Assembly"
public class dog: Ianimal
{
string myColor
{
get{return "black";}
}
}

// my main Assembly where the "magic" happens.
//Initialy only knows the "global assembly"
pubilc class myMainClass
{
Type AnimalType;

void DynamiclyLoadAssembly(string assemblyFileName)
{ //ommitted,but this is where AnimalType is defined}

private Ianimal[] myAnimals;

void SomeFunction(int x)
{
Ianimal[x] = (Ianimal) (new AnimalType());
}

private SerializeAnimals(Ianimals[] myAnimals )
{//ommitted}

private DeserializeMyAnimals()
{
//Q: If the next time I run the app, and I dont load the "Dog Assembly",
// will this fail?????????????????????????????
}
}
Thanks in advance.
Jan 12 '07 #3

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

Similar topics

14
by: vince | last post by:
Can I add (append) to an xml file that already contains a serialized object, and be able to deserialize to either or both objects from the same file...??? How is this done...?? thanks, vince
5
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream...
0
by: Mike Pollett | last post by:
Hi, I have used the ISerializable interface before and the code below worked fine. Until I derived it from CollectionBase. The code will still serialize and deserialize the properties in this class...
1
by: Mike Pollett | last post by:
Hi, I have used the ISerializable interface before and the code below worked fine. Until I derived it from CollectionBase. The code will still serialize and deserialize the properties in this class...
1
by: Marcin | last post by:
hi, I would like to ask how to serialize class with members like SqlParameter. I try to use BinaryFormatter. public class Example_Class { public SqlParameter sqlParam; public...
1
by: Gianmaria | last post by:
Hi, how do i deserialize a composite object my object have this structure... obj |_ leaf |_subObj |_leaf
7
by: Ben Amada | last post by:
I've created a class that I need to store in ViewState. However when I try to store it in ViewState, I get the following error: "The type 'solution.pe2' must be marked as Serializable or have a...
5
by: Brad | last post by:
I would like to serialize an arraylist of objects to xml so I can store the xml in a database column. How would I code the serializing and deserializing? Below is a (overly) simple, incomplete...
3
by: Mirek Endys | last post by:
What is the best way to serialize object, that contains data in interfaces. Simple. I have instance of my object, that contains data in interfaces. What is the best way to XMLSerialize and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
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...
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.