Strong name binary serialization and versioning problem

T

Tamir Khason

Hi, all
Two classes Foo1 and Foo2
Foo1 uses Foo2 as reference
Both are strong name signed with the same key pair
I'm performing Binary Serialization of object inside Foo2 from Foo1
as following:
------------------------------
IFormatter f = new BinaryFormatter();
Stream s = new FileStream(fileName,FileMode.Create,FileAccess.Write,
FileShare.None);
f.Serialize(s,graph);
s.Close();
----------------------------
and then Deserialize:
----------------------------
IFormatter f = new BinaryFormatter();
Stream s = new FileStream(fileName, FileMode.Open, FileAccess.Read,
FileShare.Read);
graph = f.Deserialize(s);
s.Close();
----------------------------
everythink working just fine, BUT
Making any change in Foo1 or Foo2 (recompilation) [WITHOUT MAKING ANY
CHANGES IN THE OBJECT FOR DE/SERIALIZATION] cause the following exception
throw and make the saved object undeserializable thus I can not read the
object from saved file anymore

System.Runtime.Serialization.SerializationException: Cannot find the
assembly Foo2, Version=1.0.1739.20447, Culture=neutral,
PublicKeyToken=8f3506f185b212ea.

Except it everythink working fine that means that Foo1 can find and use Foo2

Please advice
 
R

Robert Jordan

Hi Tamir,
everythink working just fine, BUT
Making any change in Foo1 or Foo2 (recompilation) [WITHOUT MAKING ANY
CHANGES IN THE OBJECT FOR DE/SERIALIZATION] cause the following exception
throw and make the saved object undeserializable thus I can not read the
object from saved file anymore

System.Runtime.Serialization.SerializationException: Cannot find the
assembly Foo2, Version=1.0.1739.20447, Culture=neutral,
PublicKeyToken=8f3506f185b212ea.

Strongnames drives the CLR to use a more strict type binding.
The version number becames part of the assembly name.
Because your version number is automatically computed,
you get after every recompile a new incompatible assembly.

You should manually maintain the version number of the assembly.

bye
Rob
 
T

Tamir Khason

are there ways to take care on it I need versioning control in this app.

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

Robert Jordan said:
Hi Tamir,
everythink working just fine, BUT
Making any change in Foo1 or Foo2 (recompilation) [WITHOUT MAKING ANY
CHANGES IN THE OBJECT FOR DE/SERIALIZATION] cause the following exception
throw and make the saved object undeserializable thus I can not read the
object from saved file anymore

System.Runtime.Serialization.SerializationException: Cannot find the
assembly Foo2, Version=1.0.1739.20447, Culture=neutral,
PublicKeyToken=8f3506f185b212ea.

Strongnames drives the CLR to use a more strict type binding.
The version number becames part of the assembly name.
Because your version number is automatically computed,
you get after every recompile a new incompatible assembly.

You should manually maintain the version number of the assembly.

bye
Rob
 
R

Robert Jordan

Hi Tamir,
are there ways to take care on it I need versioning control in this app.

After you've persisted the data, you have to stick with the
assembly version. BTW, the last version number (the "x" from "1.0.0.x")
doesn't count.

If you cannot deal with that limitation, you have to use
binding redirects in your App.config. See "bindingRedirect element"
in the docs.

bye
Rob
 
P

Patrik Löwendahl [C# MVP]

One of my students once claimed that he solved this particular problem by
using the filter level property as so:
bin.FilterLevel = TypeFilterLevel.Low

I haven't tested this myself but maybe it helps.
 
R

Robert Jordan

Hi Patrik,
One of my students once claimed that he solved this particular problem by
using the filter level property as so:
bin.FilterLevel = TypeFilterLevel.Low

I haven't tested this myself but maybe it helps.

One of my collegues proved that it wouldn't help ;-)
But he tried to *deserialize* already serialized
data. Probably it would help if the objects were
already serialized with TypeFilterLevel.Low.

bye
Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top