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

Serialization and inheritance

Hello,

I'm getting an error when I try to serialize a class in my project. Hope
someone can help me out:

Shared assembly:

[Serializable]
public abstract class Person
{
public int PersonData;
}

Project1

[Serializable]
public class Student : Person
{

}

Person person1 = new Student();

Project2:

I like to serialize person1 (using .net remoting) so I can use that object
in this project. Project2 only knows the person class, but that is enough
since I only need to access PersonData and nothing else. When I try this i'm
getting a serializable exception that says that project2 cannot find
Project1. But I don't want to include project1 or the student class. Is
there a way to solve this / can I tell Student to only serialize the Person
data in some way?

greets,

Gerben.
Nov 17 '05 #1
3 1554
Gerben,

Unfortunately, no, you can not. You need to have a reference to the
assembly that contains the type you are going to serialize so that the
serialization framework will be able to load the appropriate type/field data
for serialization.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Gerben" <pl***********@home.nl> wrote in message
news:dl*********@news1.zwoll1.ov.home.nl...
Hello,

I'm getting an error when I try to serialize a class in my project. Hope
someone can help me out:

Shared assembly:

[Serializable]
public abstract class Person
{
public int PersonData;
}

Project1

[Serializable]
public class Student : Person
{

}

Person person1 = new Student();

Project2:

I like to serialize person1 (using .net remoting) so I can use that object
in this project. Project2 only knows the person class, but that is enough
since I only need to access PersonData and nothing else. When I try this
i'm getting a serializable exception that says that project2 cannot find
Project1. But I don't want to include project1 or the student class. Is
there a way to solve this / can I tell Student to only serialize the
Person data in some way?

greets,

Gerben.

Nov 17 '05 #2
Gerben... Net1.1 serialization was version specific. Net2.0 suppports
backward compatibility of versioning if you declare the new methods as
optional. I cannot find a reference to this online right now, but this
approach could be helpful.

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #3
That's a pity. Forces me to move my student class to the shared assembly, it
isn't neat, but it works.

Thanks for your fast reply,

Gerben.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP14.phx.gbl...
Gerben,

Unfortunately, no, you can not. You need to have a reference to the
assembly that contains the type you are going to serialize so that the
serialization framework will be able to load the appropriate type/field
data for serialization.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Gerben" <pl***********@home.nl> wrote in message
news:dl*********@news1.zwoll1.ov.home.nl...
Hello,

I'm getting an error when I try to serialize a class in my project. Hope
someone can help me out:

Shared assembly:

[Serializable]
public abstract class Person
{
public int PersonData;
}

Project1

[Serializable]
public class Student : Person
{

}

Person person1 = new Student();

Project2:

I like to serialize person1 (using .net remoting) so I can use that
object in this project. Project2 only knows the person class, but that is
enough since I only need to access PersonData and nothing else. When I
try this i'm getting a serializable exception that says that project2
cannot find Project1. But I don't want to include project1 or the student
class. Is there a way to solve this / can I tell Student to only
serialize the Person data in some way?

greets,

Gerben.


Nov 17 '05 #4

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

Similar topics

37
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined...
2
by: Daniel Faensen | last post by:
As a good OO programmer that I hopefully am I prefer to implement against interfaces rather than classes. This is especially useful when it comes to multiple inheritance which is as you know an...
0
by: uAsking | last post by:
I'm building a client side application that uses webservices. In the client application I'm inheriting from basic types used by the webservices, so the wevservice provides the classes and sets all...
4
by: Jeff T. | last post by:
Hello, I have an existing set of C# classes that encapsulate our application data. They are in a heirachy with each subclass defining more specific types of data. I would like to serialize these...
1
by: Maheal | last post by:
I have been trying to Serialize an object that is the child of another object which is also serializable. Here is the simplified scenario (assume missing code is correct): class One :...
3
by: Aaron Clamage | last post by:
Hi, I'm not sure that if this is the right forum, but any help would be greatly appreciated. I am porting some java serialization code to c# and I can't figure out the correct way to do it. ...
4
by: Mark Sizer | last post by:
Hi people, I'm having trouble trying to achieve something in C# and win forms, and am looking for a little advice if anyone has a moment. I've got two classes: 1) a base class 2) a derived...
0
by: Goethals Frederik | last post by:
Hi, I have some questions that are a little difficult to explain, so I give it a try... I have an application (aSP.NET with VB.NET codebehind) and I would like to store my data on disk...
2
by: Kevin Burton | last post by:
Hopefully this is the right group. I am getting the following exeption: Member 'PPRP602AType.RPLY_HEADER' hides inherited member 'REPLYType.RPLY_HEADER' , but has different custom attributes....
6
by: John Glover | last post by:
I'm having a very strange problem with XML serialization. I'm writing web services which pass instances of various classes back and forth as parameters and return values of web methods. The...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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:
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
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...

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.