gpt4 book ai didi

c# - Asp.NET MVC 4 WebApi 升级 - RC 到 4.0.30506.0

转载 作者:行者123 更新时间:2023-11-30 17:53:37 29 4
gpt4 key购买 nike

我遇到了一个问题,当第一个生产版本 Asp.NET WebApi 被引入并且人们从发布候选版本升级到它时,许多其他人似乎已经回到了这个问题......

尽管我现在对情况有了更好的了解,并且认为我已经缩小了问题范围,但我已经尝试了一天在网上找到的所有解决方案,但都没有成功。

具体来说,我的应用程序(无论是部署到我的本地 IIS 服务器,还是在开发服务器中运行)似乎正在使用较旧的 System.Web.Http 程序集。

Application_Start() 方法的第二行因异常而失败

protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();

**WebApiConfig.Register(GlobalConfiguration.Configuration);**
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}

从包含模板的 WebApiConfig.cs 文件/类调用 ​​Register 方法:

public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}

调用 config.Routes.MapHttpRoute() 会导致以下异常:

Method not found: 'System.Web.Http.Services.DependencyResolver System.Web.Http.HttpConfiguration.get_ServiceResolver()'.

Server stack trace:
at System.Web.Http.GlobalConfiguration.<.cctor>b__0()
at System.Lazy`1.CreateValue()

Exception rethrown at [0]:
at System.Web.Http.GlobalConfiguration.<.cctor>b__0()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Lazy`1.get_Value()
at System.Web.Http.GlobalConfiguration.get_Configuration()
at MvcApplication2.WebApiApplication.Application_Start()
in C:\Projects\TestArea\ASP_MVC\4\MvcApplication2\Global.asax.cs:line 21

到目前为止我所做的事情是:

  • 重新安装所有版本的 .NET
  • 从 GAC 中删除 System.Web.Http
  • 确保项目引用指向 WebApi 目录,而不是操作系统的 .NET 程序集
  • 确保项目引用设置为“复制本地”
  • 从 c:\windows\system32\inetsrv\和 c:\inetpub 中删除了 IIS 的临时文件
  • 运行 c:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe
  • 通过 NuGet 更新了所有 WebApi 相关包
  • 停止和启动 IIS 和站点
  • 重新启动

ServiceResolver 方法在普通的 .NET System.Web.Http 中不存在,仅在 System.Web.Http 的 WebApi 版本中存在,这就是为什么我认为它引用了错误的程序集。

我只是不知道还能做什么。任何帮助深表感谢。谢谢。

最佳答案

既然Samus自己找到了答案,我就把它贴在这里作为官方答案。

我认为解决方案是检查加载的各种 DLL 的输出窗口,查找仍在使用 RC 版本的版本,找到它们的位置并将它们删除。

在他的案例中,这是因为 RC 显然向 GAC 添加了一些 DLL(这在 MVC4 的发布版本中不再完成,因为它们都是 bin-deployed)。

关于c# - Asp.NET MVC 4 WebApi 升级 - RC 到 4.0.30506.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17125889/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com