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?
views:
73answers:
2
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
2009-07-22 20:31:48
Can you post the specific error you are receiving?
2009-07-24 15:36:17
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.
2009-07-24 16:41:19
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
2009-07-24 19:33:24
The location remains the same: `%userprofile%\Local Settings\Application Data\Company\Product` This location is selected automatically by the Framework.
jasonh
2009-07-24 19:38:47
+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
2009-10-26 15:17:10