'C#: Storing a .Net Object in the Registry

Is it possible to store a .Net object in the registry?

I want to store a generic List<> in the registry, and then retrieve it and parse it back to the List.

Is this possible, or do I need to manually serialize it and then deserialize it back?

[UPDATE]

Following the posted answers, I am going to serialize the object and save it in the Current User's AppData folder.



Solution 1:[1]

It's possible, if the type included in the list is serializable. If that's the case, you can serialize it and store it in a string value.

But it's probably a very bad idea. The registry gets big enough as it is. Instead, put this kind of thing on the file system, in the All Users Application Data folder.

Solution 2:[2]

Yeah, I think you'd have to serialize and deserialize it yourself. But you could store it either as a binary block or text/xml. It's possible that there is a size limit to registry data...

The big question is "is this a good thing to do?"

Solution 3:[3]

You will have to serialize it yourself. Beware that there might be limitations on the amount of data you can store, depending on the Windows version.

http://msdn.microsoft.com/en-us/library/ms724872(VS.85).aspx

Solution 4:[4]

I'll just say this first: this sounds like a really bad idea.

If you insist on doing this, you're going to have to serialize it first. The registry doesn't support inserting .NET objects.

Solution 5:[5]

You would have to serialize it. The registry only stores primitive values.

Solution 6:[6]

You would need to manually serialize it.

Solution 7:[7]

Not quite sure why you'd want to store .NET objects in the registry, as there's already existing functionality in the BCL that allows you to do this with XML configuration files... but saying that, it is of course possible to store .NET objects in the registry. You'd probably only want to do it if the size of the object was relatively small, but it shouldn't be a problem anyway. I guess that the obvious way to do it would be to use XML Serialization (without formatting/whitespace) and store the object as a serialized string value.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Jeff Kotula
Solution 3 mmx
Solution 4 Alex Fort
Solution 5 John Saunders
Solution 6 Jason Coyne
Solution 7 Noldorin