65.9K
CodeProject 正在变化。 阅读更多。
Home

Web.config 中的程序集重定向不起作用(程序集绑定错误)

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0投票)

2013 年 10 月 11 日

CPOL
viewsIcon

12503

我在 web.config 中使用程序集重定向时遇到了问题,当我将重定向写入 machine.config 时,它工作正常,但是当我

我在 web.config 中使用程序集重定向时遇到了问题,当我将重定向写入 machine.config 时,它工作正常,但是当我将其写入 web.config 时,它不起作用

问题

在使用 Visual Studio 2005 创建的项目中,尝试在 web.config 中进行程序集重定向时,它不起作用,但在 machine.config 中却可以。 

<runtime>

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

<dependentAssembly>

<assemblyIdentity name="TestLibrary" publicKeyToken="c417d4d39ba0d6b2" culture="neutral" />

<bindingRedirect oldVersion="1.0.0.0" newVersion="1.1.0.0" />

</dependentAssembly>

</assemblyBinding>

</runtime>

解决方案
问题出在这一行:<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> web.config 的开头。 .NET 会自动创建 xmlns 标签并将其设置为 http://schemas.microsoft.com/.NetConfiguration/v2.0,显然这导致了我的应用程序中的问题。我删除了 xmlns 标签,即我将其写成:<configuration> ,一切都正常工作了
© . All rights reserved.