无法加载文件或程序集'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling

发布于 2024-10-13 06:33:28 字数 4008 浏览 4 评论 0原文

当我为 wcf 应用程序添加 Enterprise Library 5.0 文件 MS.Practices.EnterpriseLibrary.ExceptionHandling.dll 时,出现以下错误。

为异常处理创建配置节处理程序时发生错误:无法加载文件或程序集“Microsoft.Practices.EnterpriseLibrary.ExceptionHandling,Version=2.0.0.0,Culture=neutral,PublicKeyToken=null”或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。

 <exceptionHandling>
<exceptionPolicies>
  <add name="Global Policy">
    <exceptionTypes>
      <add name="Exception" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="None">
        <exceptionHandlers>
          <add name="Wrap Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WrapHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" exceptionMessage="Global Message." wrapExceptionType="ExceptionHandlingQuickStart.BusinessLayer.BusinessLayerException, ExceptionHandlingQuickStart.BusinessLayer" /> 
          <add name="Custom Handler" type="AppMessageExceptionHandler, ExceptionLibraryForWCF"/>
        </exceptionHandlers>
      </add>
    </exceptionTypes>
  </add>
  <add name="Handle and Resume Policy">
    <exceptionTypes>
      <add name="Exception" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="None">
        <exceptionHandlers/>
      </add>
    </exceptionTypes>
  </add>
  <add name="Propagate Policy">
    <exceptionTypes>
      <add name="Exception" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="NotifyRethrow">
        <exceptionHandlers/>
      </add>
    </exceptionTypes>
  </add>
  <add name="Replace Policy">
    <exceptionTypes>
      <add name="SecurityException" type="System.Security.SecurityException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="ThrowNewException">
        <exceptionHandlers>
          <add name="Replace Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ReplaceHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" exceptionMessage="Replaced Exception: User is not authorized to peform the requested action." replaceExceptionType="System.ApplicationException, mscorlib"/>
        </exceptionHandlers>
      </add>
    </exceptionTypes>
  </add>
  <add name="Wrap Policy">
    <exceptionTypes>
      <add name="DBConcurrencyException" type="System.Data.DBConcurrencyException, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="ThrowNewException">
        <exceptionHandlers>
          <!--<add name="Wrap Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WrapHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" exceptionMessage="Wrapped Exception: A recoverable error occurred while attempting to access the database." wrapExceptionType="ExceptionHandlingQuickStart.BusinessLayer.BusinessLayerException, ExceptionHandlingQuickStart.BusinessLayer" /> -->
        </exceptionHandlers>
      </add>
    </exceptionTypes>
  </add>
</exceptionPolicies>

下面是我的异常处理的 web.config 声明 -->

I get this below error when i add Enterprise library 5.0 file MS.Practices.EnterpriseLibrary.ExceptionHandling.dll for my wcf application.

An error occurred creating the configuration section handler for exceptionHandling: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.

 <exceptionHandling>
<exceptionPolicies>
  <add name="Global Policy">
    <exceptionTypes>
      <add name="Exception" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="None">
        <exceptionHandlers>
          <add name="Wrap Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WrapHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" exceptionMessage="Global Message." wrapExceptionType="ExceptionHandlingQuickStart.BusinessLayer.BusinessLayerException, ExceptionHandlingQuickStart.BusinessLayer" /> 
          <add name="Custom Handler" type="AppMessageExceptionHandler, ExceptionLibraryForWCF"/>
        </exceptionHandlers>
      </add>
    </exceptionTypes>
  </add>
  <add name="Handle and Resume Policy">
    <exceptionTypes>
      <add name="Exception" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="None">
        <exceptionHandlers/>
      </add>
    </exceptionTypes>
  </add>
  <add name="Propagate Policy">
    <exceptionTypes>
      <add name="Exception" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="NotifyRethrow">
        <exceptionHandlers/>
      </add>
    </exceptionTypes>
  </add>
  <add name="Replace Policy">
    <exceptionTypes>
      <add name="SecurityException" type="System.Security.SecurityException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="ThrowNewException">
        <exceptionHandlers>
          <add name="Replace Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ReplaceHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" exceptionMessage="Replaced Exception: User is not authorized to peform the requested action." replaceExceptionType="System.ApplicationException, mscorlib"/>
        </exceptionHandlers>
      </add>
    </exceptionTypes>
  </add>
  <add name="Wrap Policy">
    <exceptionTypes>
      <add name="DBConcurrencyException" type="System.Data.DBConcurrencyException, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="ThrowNewException">
        <exceptionHandlers>
          <!--<add name="Wrap Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WrapHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" exceptionMessage="Wrapped Exception: A recoverable error occurred while attempting to access the database." wrapExceptionType="ExceptionHandlingQuickStart.BusinessLayer.BusinessLayerException, ExceptionHandlingQuickStart.BusinessLayer" /> -->
        </exceptionHandlers>
      </add>
    </exceptionTypes>
  </add>
</exceptionPolicies>

Below is my web.config declaration for my exception handling

-->

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

红ご颜醉 2024-10-20 06:33:28

您的 web.config 实际上不在帖子中。

无论如何,您的配置文件中都有对 Entlib 2.0 的引用。您需要更新以指向 Entlib 5 版本号和公钥令牌。它可能在你的元素中,但如果它在那里,如果你的文件的其余部分也有错误的版本#,我不会感到惊讶。

[进一步反思更新]

实际上,根据错误消息,还有另一种可能性 - 运行时在加载时找到 2.0 程序集而不是 5.0 程序集。仔细检查所有程序集引用,并检查 bin 目录 - 确保其中包含正确的程序集。

您还可以尝试在 Web 服务器上运行 fuslogvw 工具 - 它会告诉您运行时尝试加载哪些程序集以及在哪里查找它们。

Your web.config isn't actually in the post.

In any event, you've got a reference to Entlib 2.0 in your config file. You need to update to point at the Entlib 5 version number and public key token. It's probably in your element, but if it's there I wouldn't be surprised if the rest of your file also had the wrong version #'s.

[update on further reflection]

Actually, based on the error message, there's another possibility - the runtime is finding the 2.0 assembly instead of the 5.0 assembly when it goes to load. Double check all your assembly references, and check your bin directory - make sure it's got the right assembly in it.

You can also try running the fuslogvw tool on the web server - it'll tell you what assemblies the runtime tried to load, and where it looked for them.

飘落散花 2024-10-20 06:33:28

我也遇到过由源代码控制引起的类似问题。在同事更新项目后,我签入了项目文件的旧副本。我只是发现错误引用程序集/项目引用的项目,删除了引用,重新添加了引用并重新构建了解决方案。宾果游戏。

I had a similar problem caused by source control. I checked in an old copy of a project file after a coworker updated a project. I simply found the project that was referencing the assembly/ project reference in error, removed the reference, re-added the reference and rebuilt the solution. bingo.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文