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

Serialization problem, "is not marked as serializable" error for UserControl

Hi,

I am serializing a custom class holding some data for my project.

This data internally contains a class which contains an event

public delegate void MemberModifiedEventHandler(object sender,
MemberModifiedEventArgs e);

/// <summary>

/// Occurs on modification in a group.

/// </summary>

public event MemberModifiedEventHandler OnMembersModified;

This sender brings in a CutomPage derived from
System.Windows.Forms.UserControl.

I do not need to serialize this class as it contains only UI and has
got nothing to be saved and serialized.

But when i serialize the data it gives the error "CutomPage is not
marked as serializable".

How can i come across this problem without serializing this page.

NonSerializable attribute does not work for events and classes.

How can i serialize my data without serializing these usercontrol
clases.

Waiting for a kind reply.

Thanks & Regards

Nirdesh Dabas

ni********@yahoo.com

Aug 27 '07 #1
5 20078
Nirdesh wrote:
Hi,

I am serializing a custom class holding some data for my project.

This data internally contains a class which contains an event

public delegate void MemberModifiedEventHandler(object sender,
MemberModifiedEventArgs e);

/// <summary>

/// Occurs on modification in a group.

/// </summary>

public event MemberModifiedEventHandler OnMembersModified;

This sender brings in a CutomPage derived from
System.Windows.Forms.UserControl.

I do not need to serialize this class as it contains only UI and has
got nothing to be saved and serialized.

But when i serialize the data it gives the error "CutomPage is not
marked as serializable".

How can i come across this problem without serializing this page.

NonSerializable attribute does not work for events and classes.

How can i serialize my data without serializing these usercontrol
clases.
This is likely due to the event handler in the control bound to the
event. This means that the event containing class has a reference to
the handler containing class.

By default .net serializes all these things, so if you want to get rid
of this, you have to implement ISerializable on your data containing
class.

FB


--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Aug 28 '07 #2
By default .net serializes all these things, so if you want to get
rid
of this, you have to implement ISerializable on your data containing
class.
Or just tell it not to; for instance:

[field: NonSerialized]
public event EventHandler SomeEvent;

(the "field:" refers to the backing-field that .NET generates to hold
the delegate for this event)
Aug 28 '07 #3
Marc Gravell wrote:
By default .net serializes all these things, so if you want to get
rid of this, you have to implement ISerializable on your data
containing class.

Or just tell it not to; for instance:

[field: NonSerialized]
public event EventHandler SomeEvent;

(the "field:" refers to the backing-field that .NET generates to hold
the delegate for this event)
Hmm, didn't know that, is that new in .net 2.0? I fought with event
handler serialization in .net 1.x mostly and after that it became more
or less a default for me to implement ISerializable.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Aug 29 '07 #4
Hmm, didn't know that, is that new in .net 2.0?

Well, I've ditched my 1.1 tools so I can't check, but
NonSerializedAttribute appears in MSDN2 with a 1.1 entry so I assume
so. Very easily missed, however. The "field" bit I only found out
about a little while ago; until then I'd been adding a field / add /
remove to achieve the same (which is pretty-much what the field:
syntax does), something like [notepad code; not checked]:

[NonSerialized]
private EventHandler _someEvent;

public event EventHandler SomeEvent {
add {_someEvent += value;}
remove {_someEvent -= value;}
}

Marc
Aug 30 '07 #5
Marc Gravell wrote:
Hmm, didn't know that, is that new in .net 2.0?

Well, I've ditched my 1.1 tools so I can't check, but
NonSerializedAttribute appears in MSDN2 with a 1.1 entry so I assume
so. Very easily missed, however. The "field" bit I only found out
about a little while ago; until then I'd been adding a field / add /
remove to achieve the same (which is pretty-much what the field:
syntax does), something like [notepad code; not checked]:

[NonSerialized]
private EventHandler _someEvent;

public event EventHandler SomeEvent {
add {_someEvent += value;}
remove {_someEvent -= value;}
}
I did know about NonSerialized, but not about the 'field:' fragment.
:) That one alone could have saved me a lot of time! :) Oh well...

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Aug 30 '07 #6

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

Similar topics

3
by: Dmitry | last post by:
Hi, I have defined interface for COM components which inludes an argument being filled with additional error info, if such occurs. If inside I raise COM Error, I populate that parameter. In COM...
0
by: Orly Junior | last post by:
Gentlemen, I am working with .Net Remoting, but I am running into many problems. Probably due to the fact that I am not very experienced with that new technology. The question is... after...
0
by: Gianni Mariani | last post by:
I'm trying to make a generic factory that provides a placement new as well as the accompanying destructor. To do a down-cast I used a static_cast but it turns out that this is not always a...
1
by: n_o_s_p_a__m | last post by:
My web service has a webmethod whose return type is declared as an interface type, for example: public IBusinessProcess GetBusinessProcess() {} which generates the lovely error: Cannot...
2
by: Mike | last post by:
Hello. I am using C# in .NET v1.1. I am trying to serialize an object to disk and read it back again. The serialization seems to work OK (at least, it completes without error). However, I get...
2
by: forwardtrends | last post by:
I am trying to simply make a div appear and dis-appear. The code I am using is: --- if(!document.getElementById) { document.getElementById = function() {return null;}; } function...
1
by: Evan | last post by:
template <class CharT > struct ctype_byname { ctype_byname(); }; template < > ctype_byname<char>::ctype_byname<char>(); This code compiles with GCC 3.4.4, Sun CC 5.8, and MSVC 7.1. It...
5
by: Zytan | last post by:
I am trying to pass a variable that has been disposed into a function that accepts an object, and I get this exception. What does it mean? Why can't I pass in *anything* into a parameter of type...
5
by: Aneesh Pulukkul[MCSD.Net] | last post by:
How to convert a "Non Serializable" object to byte array. The object is a dynamically created Excel workbook. As per my understanding an object can be written and read from a stream Only if it's...
6
Markus
by: Markus | last post by:
I'm adding to my script a section that allows a thumbnail to be created and saved. I get this error: Warning: imagejpeg() : Unable to open '../uploads/thumb/' for writing: Is a directory in...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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...

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.