I found the answer. I'm posting it here in case anyone else runs into
this problem.
You write a SerializationBinder routine. It gets called during the
deserialization process and you can switch types to whatever the new
type is in the new project.
I found the code on msdn and modified it. Here is the Binder:
sealed class Version1ToVersion2DeserializationBinder : SerializationBinder
{
public override Type BindToType(string assemblyName, string typeName)
{
Type typeToDeserialize = null;
String myAssembly = Assembly.GetExecutingAssembly().FullName;
// The following line of code creates the new type,
using the current assembly
typeToDeserialize = Type.GetType(String.Format("{0},
{1}", typeName, myAssembly));
// if the type is null, its a System type, not one from
our assembly
if (typeToDeserialize == null)
{
typeToDeserialize = Type.GetType(typeName);
}
return typeToDeserialize;
}
}
And here is how it gets invoked
BinaryFormatter formatter = new BinaryFormatter();
formatter.Binder = new
Version1ToVersion2DeserializationBinder();
then you do your deserialization.
Using the debugger in the SerializationBinder helps to overcome any mismatches.
David
At 12:16 PM 1/27/2006, you wrote:
>We are converting a .Net 1.1 application to 2.0.
>We have several objects that we save in the database by serializing
>them using the binary formatter.
>When I run the converted application, it throws an error because the
>application is looking for the original type to deserialize against.
>
>Is there any way to code around this other than writing a conversion
>program to go through and upgrade all the saved objects?
>
>Thanks,
>David
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNet2/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/