MVC | Microsoft.Practices.EnterpriseLibrary.common MVC 错误

MVC | Microsoft.Practices.EnterpriseLibrary.common error in MVC

我在 MVC 中遇到以下错误

[A]Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection cannot be cast to [B]Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection. Type A originates from 'Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.Practices.EnterpriseLibrary.Common.0.414.0__31bf3856ad364e35\Microsoft.Practices.EnterpriseLibrary.Common.dll'. Type B originates from 'Microsoft.Practices.EnterpriseLibrary.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.Practices.EnterpriseLibrary.Common\v4.0_6.0.0.0__31bf3856ad364e35\Microsoft.Practices.EnterpriseLibrary.Common.dll'.","ExceptionType":"System.InvalidCastException","StackTrace":" at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection.GetConfigurationSourceSection()\r\n at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceFactory.Create()\r\n

请帮忙解决问题

您的企业库版本似乎存在版本冲突。

您应该可以通过在 <runtime><assemblyBinding> 下的 web.config 中向更高版本添加 binding redirect 来解决此问题:

<dependentAssembly>
    <assemblyIdentity name="Microsoft.Practices.EnterpriseLibrary.Common" 
                      culture="neutral" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>

您可能需要以类似方式重定向任何其他 EntLib 程序集。