473,587 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ArgumentExcepti on: "Argument passed in is not serializable"

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

Apr 1 '07 #1
5 11197
It sounds like the problem isn't passing an object - that should work
fine. The problem is that the method in question expects certain
things from that object. *what* it wants is determined by the exact
method. What method is this? As an example... string.Concat expects to
be be able to call .ToString() on the arguments... if I pass it an
object that is (for some reason) going to throw an exception
on .ToString(), then string.Concat isn't going to be happy.

Marc

Apr 1 '07 #2
Zytan <zy**********@g mail.comwrote:
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?
Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

I suspect it's the method you're passing the parameter to that's
throwing the exception, but we won't know without more context.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 1 '07 #3
Zytan wrote:
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?
Take the following example:

class Foo
{
public Foo(){ }
public override ToString(){
throw new Exception();
}
}
class Bar
{
public Bar(){ }
public void PrintObject(obj ect that){
System.Console. Println(that.To String());
}
static void Main(string[] args){
Foo foo = new Foo();
Bar bar = new Bar();
bar.PrintObject (foo);
}
}

This will compile, but when it runs, bar.PrintObject (foo) will throw an
exception at runtime, since it calls Foo.ToString()

In your own example, you're passing an object to a method, but that
method expects that object to be serializable.
Serialization is really easy in C#. You can probably just change your
class definition from

class Foo
{
....
}

to

[Serializable]
class Foo{
....
}

and make sure that all the fields that must be stored in the serialized
data are public.

Alun Harford
Apr 1 '07 #4
As a final note; "disposed"; if it has been disposed, you should
probably be hands-off, i.e. once an object is disposed it is under no
obligation to honour *any* of the things it used to do. What are you
trying to get this disposed object to do, and why?

Marc

Apr 2 '07 #5
I'm sorry, I can't remember the exact consequences of the problem.
And trying to replicate it in a small app isn't working. I made a
Timer, and disposed it, and passed it into a function that accepts
object, and it takes it in fine. Even calls ToString() on it, to
print it out.

It sounds to me, from your responses, that the object did not accept
what the function was trying to do with it (say, as you've stated,
some class that throws inside of ToString()). But, I just made a
class that throws in its ToString(), and it just says that the
exception isn't handled.

I've tried make a class with IDisposable, and implementing Dispose,
and of course, this object can be passed as an object parameter
regarding of if it is constructed or disposed.

I just can't remember the consequences that caused this. The lack of
information in google indicates this is uncommon. I think it was
during my attempt to access my logging class's file stream after it
had been disposed of (during program shutdown).

My main question was to understand what "serializab le" meant.

Thanks for your help.

Zytan

Apr 4 '07 #6

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

Similar topics

22
3322
by: Dr Duck | last post by:
GDay all, Something seems odd to me.... I wrote a simple C# function public void bind(ref object a, ref object b, bool atob) { if(atob) b = a; else
18
2220
by: DaveLessnau | last post by:
I'm trying to learn C on my own and, apparently, my brain went on vacation somewhere. I just can't figure out how to parse the following function call: "void fillDeck( Card * const wDeck, const char * wFace, const char * wSuit)" Card is aliased before that call with: "typedef struct card Card"
2
36590
by: Prakash | last post by:
Hi Friends, In my C# application, i have tried to serialize some structured data using Soapformatter. While calling the serialize funciton i got the exception message like "mscorlib....The type <Appname>.<structurename> in Assembly <Appname>, Version=1.0.2162.36249, Culture=neutral, PublicKeyToken=null is not marked as serializable."
17
4572
by: pbd22 | last post by:
Hi. How does one return a range of rows. I know that "Top 5" will return rows 0 - 5 but, how do I get 6 - 10? thanks
0
2231
mmfranke
by: mmfranke | last post by:
Hello. Hi. I'm writing a logging service that uses .NET remoting. The idea is that the service publishes an EventProcessor object that clients can access via .NET Remoting, passing it DiagnosticEvent objects for processing. I've altered the main program for the service slightly so that I can run it more easily as a "regular" application...
94
30252
by: Samuel R. Neff | last post by:
When is it appropriate to use "volatile" keyword? The docs simply state: " The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock Statement (C# Reference) statement to serialize access. " But when is it better to use "volatile" instead of "lock" ?
5
21217
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.
3
1576
by: Rob | last post by:
I have these classes (elided methods): class Base { public: Base(string name) {...} }; class Derived : public Base {
1
1945
tlhintoq
by: tlhintoq | last post by:
I'm pretty sure this is language independent and is going to be the same whether it's VC or C# - but my project is C# WIndows Forms just in case. Does anyone have a good handle on the sequence of events when an event is raised and multiple classes are all subscribed to the event? Does each class get a copy of the argument? Does each...
0
7920
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...
0
8215
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. ...
1
7973
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...
1
5718
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...
0
5394
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...
0
3844
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...
0
3879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2358
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
0
1189
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...

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.