Serializing hashtable in library

Posted on 2006-05-02
Last Modified: 2008-01-09

I'm trying to serialize my own hashtable which contains another hashtable object that's located in a library. I've marked most of the classes in the library as [Serializable], that appeard to be working at first, but at the end I get:

Failed to serialize. Reason: Type 'System.Threading.Thread' in Assembly 'mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.

How do I get further now? I can't seem to get it right.

Thanks for reading.
Question by:valvet
    LVL 23

    Assisted Solution

    It seems that you have a public propety or class memeber of type Thread in your classes. Make it private or mark it non serializable.

    Author Comment


    The only public thread related is a propery field:

    public ThreadPriority ThreadPriority

    which I can set from the main program referencing the library.

    The rest are either private or internal. I'll try and remove this priority and see what happends.

    I should mention that I have some events in the library which the main program uses. These two are public delegate and public event.
    LVL 14

    Expert Comment

    What kind of values are you putting in the Hashtable? If any of those includes a Thread it will be almost unpossible to serialize unless you do what naveenkohli suggests.

    Author Comment

    I'm inserting a long value as the key, then the entire Hashtable object from the library as the value.

    eg: o.Add(something, HashtableObjectFromLibrary);

    Perhaps if I copied the HashtableObjectFromLibrary to a local temporary hashtable and then added that instead, so it would be like:

    Copy(HashtableObjectFromLibrary, SomeLocalHashtable);

    Then do: o.Add(something, SomeLocalHashtable);

    Author Comment

    This is all done inside a thread in the main program which runs off an event from the library.

    Author Comment


    Now I tried changing it a bit, so now I'm storing the entire class from the library as an object in the Hashtable.

    o.add(something, objectofclass);

    I'm still getting threading issues. Is this realted to my events? They're of type public delegate and public event, which the main program has a thread running on.
    LVL 14

    Accepted Solution

    Yes, that most likely is causing the problem, since it tries to serialize the events also, which results in serializing a thread. In the end you'll most likely end up serializing the whole world =). Mark the delegate/event(s) as nonserializable and it should work i think.

    Author Comment

    Hehe, you\re right. Marking the delegates and events dident work, but doing it on the private declarations Thread, ManualResetEvent got past that.. now it complains about:

    Failed to serialize. Reason: Type 'System.Diagnostics.Process' in Assembly 'Sys

    This could go very far.

    Ill just keep going marking everything as NonSerialize.

    Let me see if I can figure out how to split this.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now