NonSerialized System.Diagnostics.Process member

  • Thread starter Thread starter Steve Bloomfield
  • Start date Start date
S

Steve Bloomfield

I have a Serializeable class with a public member variable of type
System.Diagnostics.Process. I don't want to serialize this, nor is it
possible to serialize it. So I added the [NonSerialized] attribute to
the type. But, I'm still getting an exception that I am trying to
serialize the Process class.

To be specific:
System.InvalidOperationException: The type
'System.Diagnostics.Process' cannot be serialized because its
parameterless constructor is decorated with declarative security
permission attributes. Consider using imperative asserts or demands in
the constructor.

If I change the variable to private instead of public then it works,
but I need this to be public. I tried using a private variable with a
public, read-only property and it tries serialize it. I tried
wrapping the Process member inside a non-serialized class and it tries
to serialize it.

I am using serialization with MSMQ and have not tried serializing to a
file.
 
Back
Top