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