473,804 Members | 3,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 MemberModifiedE ventHandler(obj ect sender,
MemberModifiedE ventArgs e);

/// <summary>

/// Occurs on modification in a group.

/// </summary>

public event MemberModifiedE ventHandler OnMembersModifi ed;

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

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********@yaho o.com

Aug 27 '07 #1
5 20113
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 MemberModifiedE ventHandler(obj ect sender,
MemberModifiedE ventArgs e);

/// <summary>

/// Occurs on modification in a group.

/// </summary>

public event MemberModifiedE ventHandler OnMembersModifi ed;

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

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
NonSerializedAt tribute 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
NonSerializedAt tribute 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
1983
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 environment this architecture works beautifully -- caller application gets negative HRESULT and error description from IErrorInfo object, and additional "log" information from that "ref" parameter: In .Net it just never returns that paramter...
0
1376
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 implementing the remote type, a host application and the client, I'm having problems with the serialization that happens during the remote method calls.
0
1156
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 possible because of virtual inheritance. What I'd like to do is provide an automatic way of deciding to use a dynamic or static cast depending on if it's possible to static_cast. The jist of what I want to do is below but I know it's wrong. Any...
1
13646
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 serialize interface IBusinessProcess
2
1808
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 the following error when trying to deserialize: An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll
2
15181
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 setStyle(element, property, value) {
1
1272
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 fails
5
11234
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 object? Doesn't it cover them all? Zytan
5
21244
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 serialized. Any ideas? Thanks in advance.
6
6806
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 /home/.gobbles/mahcuz/mahcuz.com/upload/uploaded.php on line 129 And this is some of the code from the page: /* New code for thumbnails. Will on work if user selects "create thumb on upload" on the upload page */ //check to see if checkbox is...
0
9588
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
10589
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...
1
10327
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7625
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
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3828
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2999
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.