views:

201

answers:

2

In the application(C#) I am maintaining, there are some serialized object stored in the database, and some are created several versions ago.

Now when the app tries to deserialize those objects, it throws an exception: Parse Error, no assembly associated with Xml key .... (the assembly name and version)

As I understand it, when the SoapFormatter tries to deserialize the object, it first checks if the deserializing assembly is the same as serializing assembly, and if not it will throw the above error message. Would this be the case?

If it is the case, is there a way to convert those old data to make them readable by the newest version of the app?

On a side note, I'm thinking of writing a program to have the same assembly name and version to pretend to be the same assembly that serialized those objects, is it possible?

+1  A: 

I haven't tried this, but I wonder if you could use XSLT to transform the older version to a more recent "version" structure.

Jordan S. Jones
Thanks for the reply, but the serialized objects are not in XML but in some sort of binary data like "PFNPQVAtRU5WOkVudmVsb3BlIHhtbG5zOnhzaT0iaHR0cDovL3d3d...."
FlyinFish
I just realized that it is just a string converted from memorystream the xml is stored in. So now I'm able to convert that string back to XML. I will give a shot to your sugguestion, thanks Jordan!
FlyinFish
A: 

XSLT transformation mentioned by Jordan will probably work but in my case I need to change a few attribute and node names make it rather complicated.

I ended up just use Regex.Replace to convert the changed assembly names and member names, with something like this:

newData = Regex.Replace(textData, "(" + String.Join("|", keys) + ")",
                        new MatchEvaluator(this.EvaluateReplacement));

string EvaluateReplacement(Match m)
{
    if (this.convertDict.ContainsKey(m.Value))
    {
        return this.convertDict[m.Value];
    }
    return m.Value;
}

where this.convertDict is a Dictionary object that contains conversion mappings.

FlyinFish