views:

73

answers:

2

I've got a class in my project and I want to move and rename that class to somewhere else in the project's namespace. I tried simply moving it, but then the program won't deserialize any settings saved under Properties.Settings.Default for that setting. Is there a way I can move it without losing all of the user's settings?

A: 

I'll assume your using Studio, have you tried dragging the class into a Class Diagram and renaming from there? I find that Studio refactors accordingly from the Class Diagram.

The issue isn't that I can't rename the class in my code. I can do that no problem. It's when the Framework goes to deserialize the class from storage it can't find the original class it was serialized with.
jasonh
Can you post the specific error you are receiving?
Also, are the locations in which you are serializing and deserializing different? For instance, a class is serialized in an environment with Framework 1.1 and deserialized in an environment using Framework 2.0.
There's no specific error, it just doesn't deserialize the setting. Say I have version 3.0 of my product out and I have selected the `MyBadClassname` as the type for one of the properties. I decide to rename it to `DescriptiveClassname` and move it to the `MyProduct.Settings` namespace. If I do this, when I call `Properties.Settings.Upgrade()` the value for the property is an brand-new empty object instead of the object with data populated that was serialized before.
jasonh
The location remains the same: `%userprofile%\Local Settings\Application Data\Company\Product` This location is selected automatically by the Framework.
jasonh
+1  A: 

I think the SerializationBinder contains a solution for your problem.

From the MSDN documentation:

Some users need to control which class to load, either because the class has moved between assemblies or a different version of the class is required on the server and client.

GvS