I created a basic project in WinForms on which I have a .exe
that loads a really simple library:
The .exe:
public Form1()
{
InitializeComponent();
int a;
int b;
a = 7;
b = 3;
MessageBox.Show(Sumar.SumResult(a, b));
}
The library:
public class Sumar
{
public static string SumResult(int a, int b)
{
return (a + b).ToString(CultureInfo.InvariantCulture);
}
}
Really simple. The assembly for the first version of the library:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Then I installed v1.0.0.0 on GAC:
gacutil -i TestLibrary.dll
I changed code on the library to be different:
public class Sumar
{
public static string SumResult(int a, int b)
{
return (a - b).ToString(CultureInfo.InvariantCulture);
}
}
And changed assembly version to 1.0.0.1. Then I installed that library to GAC.
The .exe
is still consuming 1.0.0.0 .dll, so I create a policy to use v1.0.0.1 instead:
al /link:test.1.0.config /out:policy.1.0.TestLibrary.dll /keyfile:sgKey.snk /platform:x86
Where the .config
looks like this:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="TestLibrary"
publicKeyToken="a96822fc2f88c1d9"
cultures="neutral" />
<bindingRedirect oldVersion="1.0.0.0" newVersion="1.0.0.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
After that, I install the policy to GAC:
gacutil /i policy.1.0.TestLibrary.dll
And it says Assembly successfully added to the cache, but my .exe is still using v1.0.0.0.
So, Why didn't my redirect work?