首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GlobalConfiguration -尝试访问字段“<>9__CachedAnonymousMethodDelegate2”失败

GlobalConfiguration -尝试访问字段“<>9__CachedAnonymousMethodDelegate2”失败
EN

Stack Overflow用户
提问于 2014-04-17 21:03:33
回答 3查看 7.3K关注 0票数 4

当设置依赖关系解析器时,我会得到这个错误。

代码:

GlobalConfiguration.Configuration.DependencyResolver =新UnityDependencyResolver(容器);

错误:

方法'System.Web.Http.GlobalConfiguration..cctor()‘试图访问字段'System.Web.Http.GlobalConfiguration.CS$<>9__CachedAnonymousMethodDelegate2’失败。

我在这里错过了什么?

发布的所有解决方案都涉及安装最新版本的Microsoft.AspNet.WebApi。

安装包Microsoft.AspNet.WebApi -IncludePrerelease

但是,我已经拥有了所有最新版本的所需程序集,并且仍然会收到此错误。

代码语言:javascript
复制
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31BF3856AD364E35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
        </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
  </dependentAssembly>
</assemblyBinding>
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-04-17 23:09:16

已经安装了包,但显然有些引用是从GAC而不是从NuGet包文件夹中获取的。

这些都是手动删除的,我在packages文件夹中添加了引用,它运行正常。

(应该有一个NuGet特性来“清理”引用,这样它们就可以从packages文件夹而不是其他地方获取)。

票数 6
EN

Stack Overflow用户

发布于 2015-07-24 11:12:21

我通过安装MicrosoftWebAPI2.2来解决这个问题

票数 4
EN

Stack Overflow用户

发布于 2019-10-04 06:58:23

解决方案链接:https://www.niceonecode.com/Question/20222/The-type-initializer-for-System.Web.Http.-GlobalConfiguration-threw-an-exceptio

我有同样的问题,它的解决办法是解决它。

PM> Install Microsoft.AspNet.WebApi -Pre它将包括一个预发布版本。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23143411

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档