Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Serializing hashtable in library

Posted on 2006-05-02
Medium Priority
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
  • 5
  • 2
LVL 23

Assisted Solution

naveenkohli earned 160 total points
ID: 16589919
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

ID: 16590037

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

ID: 16590042
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.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 16590073
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

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

Author Comment

ID: 16590341

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

existenz2 earned 280 total points
ID: 16590398
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

ID: 16590572
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.

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

571 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