473,803 Members | 2,934 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Serilization problems

Hi everyone

I have a serious problem with the serilization of an user-defined object in
C#. I would like to serialize an object of class D which inherits from class
C. Class C as well as class D are marked with the compiler-attribute
[Serializable] (see also code-snippet at the end of the message).
It is no problem to serialize a instance of class C, but I got the following
error-message if I try to serialize a instance of class D:

An unhandled exception of type
System.Runtime. Serialization.S erializationExc eption: The type <Namespace>.B
in Assembly <AssemblyName >, Version=0.0.0.0 , Culture=neutral ,
PublicKeyToken= null is not marked as serializes.

The problem I have is, that the variable which causes the Exception is a
member of the base-class C which can be serialized without any problems.
In addition to that, the variable is also marked with the
[NonSerialized]-attribute, so the value of this variable should not be
serialized (see also in the code-snippet).

Thanks for any help!

greetings stephan
Code:

public class A : MarshalByRefObj ect, IDisposable
{
//some ints, Hashtables, IPAddresses (all
//Serializable)

protected A a
}
public class B : A
{
protected new B a
}
[Serializable]
public class C : MarshalByRefObj ect, IDisposable
{
[NonSerialized]
protected B a;

//some Guids and longs (all serializable)
}
[Serializable]
public class D: C
{
[NonSerialized]
private static CDBInterface cDBInterface = new CDBInterface();

//some Hashtables (all serializable)
}
Nov 16 '05 #1
3 4365
Stephan,

Using the code that you provided, I can serialize and deserialize the
instance of D no problem.

I do not think that you should "new" any of the members of the classes,
as you will have to make sure to account for both the value on the base
class and the derived class.

Can you post an example that shows the problem?

Also, you don't have to mark static members as non-serializable, as they
are not eligibile for serialization.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Stephan Schlicker" <St************ **@discussions. microsoft.com> wrote in
message news:7C******** *************** ***********@mic rosoft.com...
Hi everyone

I have a serious problem with the serilization of an user-defined object
in
C#. I would like to serialize an object of class D which inherits from
class
C. Class C as well as class D are marked with the compiler-attribute
[Serializable] (see also code-snippet at the end of the message).
It is no problem to serialize a instance of class C, but I got the
following
error-message if I try to serialize a instance of class D:

An unhandled exception of type
System.Runtime. Serialization.S erializationExc eption: The type
<Namespace>.B
in Assembly <AssemblyName >, Version=0.0.0.0 , Culture=neutral ,
PublicKeyToken= null is not marked as serializes.

The problem I have is, that the variable which causes the Exception is a
member of the base-class C which can be serialized without any problems.
In addition to that, the variable is also marked with the
[NonSerialized]-attribute, so the value of this variable should not be
serialized (see also in the code-snippet).

Thanks for any help!

greetings stephan
Code:

public class A : MarshalByRefObj ect, IDisposable
{
//some ints, Hashtables, IPAddresses (all
//Serializable)

protected A a
}
public class B : A
{
protected new B a
}
[Serializable]
public class C : MarshalByRefObj ect, IDisposable
{
[NonSerialized]
protected B a;

//some Guids and longs (all serializable)
}
[Serializable]
public class D: C
{
[NonSerialized]
private static CDBInterface cDBInterface = new CDBInterface();

//some Hashtables (all serializable)
}

Nov 16 '05 #2
Hi Nicolas
Using the code that you provided, I can serialize and deserialize the
instance of D no problem.

I do not think that you should "new" any of the members of the classes, as you will have to make sure to account for both the value on the base
class and the derived class. Yes, I now that problem! But at the moment this solution works just fine.
Can you post an example that shows the problem? I'll try to give you an example. I'm sorry that I can not post the whole
code because it's code for my master thesis and this code is also supposed
to build the base of some non-open-source software!

[Serializable]
public class C : MarshalByRefObj ect, IDisposable
{
[NonSerialized]
protected B framework;
protected Guid systemID;
protected long userID;

public C(long _userID, B _framework)
{
this.userID = _userID;
this.framework = _framework;
this.RegisterAt Framework();
}
}

[Serializable]
public class D: C
{
[NonSerialized]
private static CDBInterface cDBInterface = new CDBInterface();
[NonSerialized]
private Hashtable x = new Hashtable();
[NonSerialized]
private Hashtable y = new Hashtable();
[NonSerialized]
private Hashtable z = new Hashtable();
public CustomerManager (long userID, SimMarketAgentF ramework
framework) : base(userID, framework)
{
ArrayList d = new ArrayList();
foreach(C c in a.Values)
d.Add(c);
this.framework. Register(this.f ramework.Framew orkID, d,
this.userID);
}
}

Those are all Members of both classes and their corresponding Constructor
which I use!
After all objects are created I manually call the following method for one
speciall instance of D:

public void Send(IPAddress address, Guid iD)
{
C c = (c)this.cRefere nces[ID];
B framework = (B)Activator.Ge tObject(typeof( B), "http://" + address
+ ":1234/B.soap");

MemoryStream stream = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter ();
formatter.Conte xt = new
System.Runtime. Serialization.S treamingContext (StreamingConte xtStates.Clone) ;
formatter.Seria lize(stream, c);

bool received = framework.Recei ve(stream);

if(received)
{
c.Dispose();
this.cReference s.Remove(agentI D);
}
}

And the last statement which is executed correctly is
formatter.Conte xt(...)! The statement formatter.Seria lize(stream, c) crashes
and produces that mentioned exception!

Also, you don't have to mark static members as non-serializable, as they are not eligibile for serialization.

I don't have any static members at the moment!
Nov 16 '05 #3
> >
Also, you don't have to mark static members as non-serializable, as

they
are not eligibile for serialization.

I don't have any static members at the moment!


Hi Stephan,

This is from your code:
[NonSerialized]
private static CDBInterface cDBInterface = new CDBInterface();
I think this is what Nicholas was talking about.

--- Nick
Nov 16 '05 #4

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

Similar topics

14
2326
by: Jim Hubbard | last post by:
Are you up to speed on the difficulties in using the 1.1 .Net framework? Not if you are unaware of the 1,596 issues listed at KBAlertz (http://www.kbalertz.com/technology_3.aspx). If you are going to use .Net......I highly recommend signing up for the free KBAlertz newsletter at http://www.kbalertz.com/default.aspx. Looking at all of the errors and quirks sometimes makes me wonder if this thing is really ready for prime time.
1
3052
by: 3f | last post by:
Hello; We have made a web application that people can download from our web site and installed on: Windows XP Windows 2000 Professional Windows 2003 Server Windows 2000 Server
6
2833
by: amethyste | last post by:
hello, This is my sample (simplified): public class Binom { public string _Value;
5
8802
by: Corky | last post by:
This works: db2 SELECT DISTINCT PROBLEM_OBJECTS.PROBLEM_ID FROM PROBLEM_OBJECTS INNER JOIN PROBLEMS ON PROBLEM_OBJECTS.PROBLEM_ID = PROBLEMS.PROBLEM_ID WHERE INTEGER(DAYS(CURRENT DATE) - DAYS(PROBLEMS.CLOSE_DATE)) = 365 AND PROBLEMS.CLOSE_DATE IS NOT NULL But this doesn't: db2 SELECT DISTINCT PROBLEM_OBJECTS.PROBLEM_ID FROM PROBLEM_OBJECTS
10
2417
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ComboBox.SelectedValue = db_value; If the db_value was not included in the ComboBox value list the ComboBox.SelectedIndex used to return -1, Now the very same code is
7
1145
by: Squigge | last post by:
Hello, I've been trying to serialize a custom object for transfer to a web services and I'm running into a lot of problems. First of all, I'm wanting to serialize the entire object, both private and public properties. It seems as though when I try to accomplish this using the XmlSerializer object, BinaryFormatter object, or the SoapFormatter object, it will only do the public properties and methods. Is there another object that will do...
0
2250
by: Sergistm | last post by:
Hello World, :D I have a problem that it is making me crazy, I hope you can help me. I'm trying to execute a .exe file with the Procces.Start, and there is no problem when the file is on my computer, the problem comes when the file is in a network drive. The most amazing thing is that in one computer I can execute my .Net program without problems independently if the file is
3
6000
by: RJA | last post by:
Hiyas, Using VS .net 2003. Setting up a Webservice that accepts 3rd party vendor designed XML requests and returns a filled XMLDocument with response data. Vendor XSDs were serialize into class objects to be used in the program. EX: Used xsd.exe to turn VendorA_Request.XSD into VendorA_Request.cs EX: Used xsd.exe to turn VendorA_Response.XSD into VendorA_Response.cs
7
1947
by: Mike9900 | last post by:
If you do .NET Remoting and Binary Serilization with DataSet it does not work. If you set the Serialization type to Binary on DataSet, it does not seralize it correctly on windows xp. To do this set the serilization to Binary and use it in remoting on Windows XP. Is there a way around this? -- Mike
0
9703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9566
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10555
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10317
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7607
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6844
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2974
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.