Unity无法加载文件或程序集'Microsoft.Practices.ServiceLocation,Version = 1.2.0.0

时间:2015-07-26 20:31:44

标签: c# dependency-injection unity-container

当我开始我的项目(基于Project Orleans)时,发现错误的引用引发了一个奇怪的警告:

 [2015-07-26 20:03:06.970 GMT 6 INFO 100000 AssemblyLoader.Client ] User assembly ignored: C:\Users\Gutemberg\Documents\Visual Studio 2015\Projects\PI - Switch (MS)\PI.Switch.Gateway.Host\bin\Debug\Microsoft.Practices.Unity.dll
* An assembly dependency [Microsoft.Practices.ServiceLocation, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Could not load file or assembly 'Microsoft.Practices.ServiceLocation, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.] could not be loaded: 0   

Microsoft.Practices.ServiceLocation不在Unity Nuget包中,我无法在任何地方找到它!这会导致我的应用程序出现一些奇怪的运行时行为。

我正在使用来自nuget的最新Unity。附上一些屏幕截图,证明VS上的依赖项(ILSpy)和项目引用+ Nuget包管理器屏幕。

Evidences

这个参考真的有必要吗?我怎么能摆脱它?

谢谢!真的很感激帮助。

1 个答案:

答案 0 :(得分:4)

尝试获取更新版本,然后重定向到该特定版本。

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
        <assemblyIdentity name="Microsoft.Practices.ServiceLocation" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
    </dependentAssembly>
</assemblyBinding>

无论如何。以下应该是您丢失的包裹吗?

https://www.nuget.org/packages/CommonServiceLocator/1.2.0