This project is read-only.
1
Vote

Issues with changed PublicKeyToken value in v4.x

description

There is a problem with Unity 4.x versions. Here are steps to reproduce it:

1 . Create "Windows -> Classic Desktop -> WPF Application" project in Visual Studio.
2 . Add "Prism.Unity" v6.0.1 NuGet package.
3 . In the "Package Manager Console" run "Update-Package" command.
4 . Add new class:
    public class Bootstrapper : Prism.Unity.UnityBootstrapper
    {
        protected override DependencyObject CreateShell()
        {
            return new MainWindow();
        }
    }
5 . In the App.xaml file remove the following attribute:
StartupUri="MainWindow.xaml"
6 . In the App.xaml.cs file add the following code:
protected override void OnStartup(StartupEventArgs e)
{
    base.OnStartup(e);

    var bootstrapper = new Bootstrapper();
    bootstrapper.Run();

    Application.Current.MainWindow.Show();
}
7 . Try to run a project.


Application crashes with an exception:
Could not load file or assembly 'Microsoft.Practices.Unity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"Microsoft.Practices.Unity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
I believe it's caused by the new assembly "PublicKeyToken" value. I've made a research and here are assembly full names for all versions of Unity:
Unity.4.0.1
Microsoft.Practices.Unity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f

Unity.4.0.0
Microsoft.Practices.Unity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f

Unity.3.5.1404.0
Microsoft.Practices.Unity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

Unity.3.0.1304.1
Microsoft.Practices.Unity, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

Unity.3.0.1304.0
Microsoft.Practices.Unity, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

Unity.2.1.505.2
Microsoft.Practices.Unity, Version=2.1.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

Unity.2.0
Microsoft.Practices.Unity, Version=2.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
As I can see starting from version 4.0.0 PublicKeyToken value has been changed. Now it causes some inconveniences that I have solving this problem. Is it a good practice to change PublicKeyToken value of an assembly? If you have to change it then maybe it's a good idea to create a separate NuGet package?

comments