将企业库注册到GAC后无法解决类型运行时错误

Phi*_*ppe 4 enterprise-library gac

我致力于将企业库程序集注册到全局程序集缓存(GAC)中.我正在使用我用自己的密钥签名的企业库5.0版,我在许多.NET 4.0应用程序中使用程序集.

成功将企业库程序集注册到GAC后,应用程序以此消息开始:

无法解析类型"Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter,Microsoft.Practices.EnterpriseLibrary.ExceptionHandling".请验证拼写是否正确或是否提供了完整的类型名称.

当我从GAC取消注册企业库程序集时,应用程序将返回到正常操作条件.

企业库程序集注册到GAC时导致应用程序失败的原因是什么?

Phi*_*ppe 7

这需要相当多的狩猎来弄清楚发生了什么.事实证明,企业库内部使用部分名称来动态加载类型.在这种情况下,企业库正在尝试动态加载Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter,因为它出现在配置文件中.

要在运行时绕过部分名称引用,只需在配置文件中输入qualifyAssembly元素(请参阅MSDN文档中的<qualifyAssembly>元素).

就我而言,我需要输入的只是这个条目:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <qualifyAssembly partialName="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" 
                       fullName="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  </assemblyBinding>
</runtime>
Run Code Online (Sandbox Code Playgroud)