在这个 Selenium 测试项目中,我直接引用了 Unity 3.0.0.0。
我有对引用 Unity 2.505.0.2 的其他 DLL 的引用。
我的 app.config 中有这个:
<runtime>
<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.0.0.0" newVersion="1.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="AutoMapper" publicKeyToken="be96cd2c38ef1005" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.2.1.0" newVersion="3.2.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
我预计它会使用 Unity V3,但它一直在尝试使用旧版本。绑定(bind)日志为:
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\vstest.executionengine.x86.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = INT\UKTHJHAR
LOG: DisplayName = Microsoft.Practices.Unity, Version=2.1.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///C:/Audatex/Retail/Development/Server/AudaRetailAdministration.AutomatedUITests/bin/Debug
LOG: Initial PrivatePath = NULL
Calling assembly : AudaRetailAdministration.AutomatedUITests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Audatex\Retail\Development\Server\AudaRetailAdministration.AutomatedUITests\bin\Debug\AudaRetailAdministration.AutomatedUITests.dll.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Microsoft.Practices.Unity, Version=2.1.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C:/Audatex/Retail/Development/Server/AudaRetailAdministration.AutomatedUITests/bin/Debug/Microsoft.Practices.Unity.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
最佳答案
我认为程序集绑定(bind)仅适用于直接引用。
可能是为了防止在单个应用程序(或应用程序域?)中使用同一程序集的不同版本
如果您使用由应用程序引用的另一个程序集版本编译的组件,则该组件的加载将失败。
如果您反编译引用旧版本 Unity 的程序集,您会看到 Unity 版本以某种方式硬编码在程序集元数据中。
这个帖子有同样的问题 Why is assembly binding redirect not working in my web site?
我确实通过在应用程序及其组件中使用相同的程序集版本解决了这个问题。这对你来说可能是不可能的。
此问题是使用 GAC 发布的复杂应用程序的缺点。现在,人们倾向于使用 nugget 包来轻松管理组件依赖关系。
关于c# - 程序集绑定(bind) - 使用了错误版本的 Unity,但为什么呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26276927/