views:

197

answers:

2
System.Runtime.Serialization.SerializationException: 
Type 'System.Threading.Thread' in Assembly 'mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.

Is there a way around that? ive added the Serializable attribute to all of my class's, but i cant add attributes to things like that, can i? and if i can, is there a way to get around that issue altogether? because i dont want to always have to add [Serializable] to everything.

PS, in my project, im dynamically compiling C# code and including it in my application.

edit one: Because of the nature of my application, everything, all events, etc, is managed my separate threads.. I cannot get away from that fact, because i need to be doing many tasks at the same time. Is there a way to get around that fact?

+5  A: 

One option would be to mark the thread object (and anything else you don't want serialized) as [NonSerializable].

You can then use whatever information you've serialized to reconstruct the non serializable objects.

Jeff Foster
+3  A: 

You can't serialize a thread, so your best bet would be to remove the dependency on Thread from any class that you need to serialize. Usually you want your serializable objects to be composed mainly of primitive fields, or references to other objects that are also serializable.

Andy White