473,396 Members | 2,039 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.

Serialization Exception

Hi,
My project is set up with 1 main form and 2 sub forms declared inside
it. Inside the main form i have declared a simulation object (class i
wrote), which is passed in as a parameter to constructors of the 2
subforms.
I am trying to issue a command from the mainform to serialize the
simulation object and save it to a file, using a binaryformatter. For
some reason, im getting a serializationexception which says that both
the main form and the sub forms must all be marked [serializable]. Why
do they need to be marked so when there are no fields of the MainForm
or ViewForm class declared in the simulation object?

Nov 17 '05 #1
7 2380
Michael,

Even though your simulation object doesn't have a field which is of a
form type, it could hold a reference (through another object it holds) to
the form. This is probably the case here. When you serialize an object, it
doesn't just serialize that object, it serializes every object it points to,
as well as every object they point to, and so on, and so on.

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

"Michael Gorbach" <mg******@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hi,
My project is set up with 1 main form and 2 sub forms declared inside
it. Inside the main form i have declared a simulation object (class i
wrote), which is passed in as a parameter to constructors of the 2
subforms.
I am trying to issue a command from the mainform to serialize the
simulation object and save it to a file, using a binaryformatter. For
some reason, im getting a serializationexception which says that both
the main form and the sub forms must all be marked [serializable]. Why
do they need to be marked so when there are no fields of the MainForm
or ViewForm class declared in the simulation object?

Nov 17 '05 #2
You can prevent the exception by implementing ISerializable instead of using the SerializeAttribute and only adding the data that
should be persisted. It is more work, but this is how the process of serialization accounts for those "special" situations.

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:Ov**************@TK2MSFTNGP15.phx.gbl...
Michael,

Even though your simulation object doesn't have a field which is of a form type, it could hold a reference (through another
object it holds) to the form. This is probably the case here. When you serialize an object, it doesn't just serialize that
object, it serializes every object it points to, as well as every object they point to, and so on, and so on.

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

"Michael Gorbach" <mg******@gmail.com> wrote in message news:11**********************@o13g2000cwo.googlegr oups.com...
Hi,
My project is set up with 1 main form and 2 sub forms declared inside
it. Inside the main form i have declared a simulation object (class i
wrote), which is passed in as a parameter to constructors of the 2
subforms.
I am trying to issue a command from the mainform to serialize the
simulation object and save it to a file, using a binaryformatter. For
some reason, im getting a serializationexception which says that both
the main form and the sub forms must all be marked [serializable]. Why
do they need to be marked so when there are no fields of the MainForm
or ViewForm class declared in the simulation object?


Nov 17 '05 #3
this is very strange ... none of the objects references holds a
reference to any form object, yet all the form objects in my program
seem to cause a serializationexception.

I dont understand how either form could possibly have gotten into the
graph of objects to be serialized.

Nov 17 '05 #4
Posting some code my help

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"Michael Gorbach" <mg******@gmail.com> wrote in message news:11**********************@g43g2000cwa.googlegr oups.com...
this is very strange ... none of the objects references holds a
reference to any form object, yet all the form objects in my program
seem to cause a serializationexception.

I dont understand how either form could possibly have gotten into the
graph of objects to be serialized.

Nov 17 '05 #5
here is some code ...
[Serializable]
class Simulation
{
RandGen myGen;
Configuration configuration;
MoveCounter moveCounter;
SimulationSettings settings;
....

class SimulationSettings
{
int n;
double kT, maxDisp, maxDispA, uH, hAngle;
vector boxSize;
....

[Serializable]
class Configuration
{
Nanoparticle[] particles;
vector boxSize;
double pEnergy;
int n;
RandGen myGen = new RandGen();
ArrayList chains = new ArrayList();

[Serializable]
class MoveCounter
{
int p_run_acceptedMoves, p_run_rejectedMoves;
int p_sim_acceptedMoves, p_sim_rejectedMoves;
int sweep_acceptedMoves, sweep_rejectedMoves;
int run_sweeps, sim_runs, sim_sweeps;

the simulation class is the one i am trying to serialize. As you can
see there are no referances to any forms in its field or any fields of
objects it references.

Nov 17 '05 #6
i think i understand whats wrong ... its the events in the simulation
class.
There are delegates listening to them that are linked to forms.
How do i fix this problem before serializing the object?

Nov 17 '05 #7
fixed it ... by doing field:nonserialized to my events

Nov 17 '05 #8

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

Similar topics

0
by: Stephan Moeller | last post by:
Hi NG, I serialize the following class over .net remoting: using System; using System.Collections; namespace JobServerLib {
0
by: HakonB | last post by:
Hi all I get an exception when trying to deserialize a simple configuration file using XML Serialization. The very long stacktrace can be seen at the bottom of this message. I've see other...
1
by: andrewcw | last post by:
There is an error in XML document (1, 2). I used XML spy to create the XML and XSD. When I asked to have the XML validated it said it was OK. I used the .net SDK to generate the class. I have...
4
by: ron | last post by:
Hi, I have class object that i serialize using the System.Xml.Serialization class. Intermittently the object is not getting serialized correctly, using System.Xml.Serialization classes....
5
by: francois | last post by:
First of all I would to to apologize for resending this post again but I feel like my last post as been spoiled Here I go for my problem: Hi, I have a webservice that I am using and I would...
6
by: Uttam | last post by:
Hello, We are at a very crucial decision making stage to select between .Net and Java. Our requirement is to download a class at runtime on the client computer and execute it using remoting or...
3
by: Steve | last post by:
I've been following a couple remoting tutorials on the web, they are all pretty much the same. I've got my different applications built(client, server and remote object (dll)) The client is...
2
by: Maximus | last post by:
Hi Everyone, I was using Inprocess session objects, but incase of aspnet process crashes the session objects were lost as a result I decided to shift to out of porocess session objects. For this...
0
by: CJ Taylor | last post by:
hey everyone, thought I would ask this here because the web service groups seems pretty light on conversation. I'm buliding a web service, but keep getting this error. I understand the error,...
8
by: =?Utf-8?B?UGlnZ3k=?= | last post by:
Hi to all, I am getting this System.OutOfMemoryException calling the Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(<stream>,<Obj>) method. The type of <streamis...
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: 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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
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...

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.