app.useMvc 处出错

Error at app.useMvc

我是 运行 ASP.NET VS 2015 CTP5 上的 Vnext 网络应用程序。

我得到一个 TypeLoadException:

An exception of type 'System.TypeLoadException' occurred in mscorlib.dll but was not handled in user code

附加信息:

Could not load type 'System.Web.Http.RouteAttribute' from assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

在这一行 -

app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller}/{action}/{id?}",
                defaults: new { controller = "Home", action = "Index" });
        });

这些是我的 project.json 中的依赖项:

"dependencies": {
    "EntityFramework.SqlServer": "7.0.0-beta2",
    "EntityFramework.Commands": "7.0.0-beta2",
    "Microsoft.AspNet.Hosting": "1.0.0-beta2",
    "Microsoft.AspNet.Diagnostics": "1.0.0-beta2",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta2",
    "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta2",
    "Microsoft.AspNet.Security.Cookies": "1.0.0-beta2",
    "Microsoft.AspNet.Server.IIS": "1.0.0-beta2",
    "Microsoft.AspNet.Server.WebListener": "1.0.0-beta2",
    "Microsoft.AspNet.StaticFiles": "1.0.0-beta2",
    "Microsoft.AspNet.Mvc": "6.0.0-beta2",
    "Microsoft.AspNet.Mvc.WebApiCompatShim": "6.0.0-beta2",
    "Microsoft.AspNet.RequestContainer": "1.0.0-beta2",
    "Microsoft.AspNet.WebUtilities": "1.0.0-beta2",
    "Microsoft.AspNet.Web.Optimization": "1.0.0-beta2",
    "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta2",
    "Microsoft.Framework.DependencyInjection": "1.0.0-beta2",
    "Microsoft.Framework.CodeGenerators.Mvc": "1.0.0-beta2",
    "Microsoft.Framework.Logging": "1.0.0-beta2",
    "Microsoft.Framework.Logging.Console": "1.0.0-beta2",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta1",
    "AutoMapper": "3.2.1",
    "Microsoft.ApplicationInsights.Telemetry.Services": "0.7.1.0",
    "Microsoft.Web.Infrastructure": "1.0.0.0",
    "Microsoft.Web.DistributedCache": "",
    "System.IdentityModel.Tokens.ValidatingIssuerNameRegistry": "4.5.1",
    "System.Spatial": "5.6.1",
    "Microsoft.WindowsAzure.ConfigurationManager": "2.0.3",
    "Microsoft.WindowsAzure.Caching": "2.5.0.0",
    "Microsoft.WindowsFabric.Common": "",
    "Microsoft.WindowsFabric.Data.Common": "",
    "Unity.WebAPI": "5.1",
    "Microsoft.Data.Edm": "5.6.2",
    "Microsoft.Data.OData": "5.6.2",
    "Microsoft.Data.Services.Client": "5.6.2",
    "WindowsAzure.Storage": "4.3.0.0",
    "Newtonsoft.Json": "6.0.8.0",
    "Unity": "3.5.1404.0"
},

您似乎在引用 system.web 这是不受支持的,您不应该那样做。查看您的 project.json 并删除对 system.web 或任何依赖于 system.web 的包的引用。

编辑: 具体来说 Microsoft.Web.Infrastructure 引用 System.Web(不受支持)。

首先逐个组件构建您的应用程序,而不是尝试将引用复制到 project.json。

您可以展开 visual studio 中的引用节点以查看每个根级别依赖项带来的依赖项。

注意 - vNext 没有可用的 oData 支持,也没有 Unity 支持,当它发生时它不会 Unity.WebAPI