【问题标题】:Unable to launch application after upgrade to Asp.net beta8升级到 Asp.net beta8 后无法启动应用程序
【发布时间】:2015-11-11 00:25:46
【问题描述】:

最近按照这些出色的说明将我的应用程序从 ASP.NET beta7 升级到 beta8:http://wildermuth.com/2015/10/20/Upgrading_from_ASP_NET_5_Beta_7_to_Beta_8

很遗憾,我仍然无法启动我的应用程序。如果我尝试使用 Kestel (web) 启动,我会在调试之前收到 500 Internal Server 错误,甚至在 Startup.cs 中遇到我的断点(它仍然会遇到我的断点)。如果我尝试在 IISExpress 中启动,我会收到以下错误:

 Could not load type 'Microsoft.Dnx.Host.Clr.EntryPoint' from assembly 'Microsoft.Dnx.Host.Clr, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

 [TypeLoadException: Could not load type 'Microsoft.Dnx.Host.Clr.EntryPoint' from assembly 'Microsoft.Dnx.Host.Clr, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.]
 System.Web.HttpRuntime.HostingInit(HostingEnvironmentFlags hostingFlags, PolicyLevel policyLevel, Exception appDomainCreationException) +303

 [HttpException (0x80004005): Could not load type 'Microsoft.Dnx.Host.Clr.EntryPoint' from assembly 'Microsoft.Dnx.Host.Clr, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.]
 System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9922864
 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +90
 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +261

我到处寻找,并与其他 beta8 示例进行比较,但无济于事。为什么我不能再启动应用程序了?这是我的适用文件-

launchSettings.json

{
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNET_ENV": "development"
      },
      "sdkVersion": "dnx-clr-win-x86.1.0.0-beta8"
    },
    "web": {
      "commandName": "web",
      "launchBrowser": true,
      "launchUrl": "http://localhost:5000",
      "environmentVariables": {
        "ASPNET_ENV": "development"
      }
    }
  }
}

项目.json

{
  "webroot": "wwwroot",
  "userSecretsId": "xxx",
  "version": "1.0.0-*",
  "dependencies": {
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta8",
    "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta8",
    "Microsoft.AspNet.Authentication.Cookies": "1.0.0-beta8",
    "Microsoft.AspNet.Authentication.Facebook": "1.0.0-beta8",
    "Microsoft.AspNet.Authentication.Google": "1.0.0-beta8",
    "Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-beta8",
    "Microsoft.AspNet.Authentication.Twitter": "1.0.0-beta8",
    "Microsoft.AspNet.Diagnostics": "1.0.0-beta8",
    "Microsoft.AspNet.IISPlatformHandler":  "1.0.0-beta8",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-beta8",
    "Microsoft.AspNet.StaticFiles": "1.0.0-beta8",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-beta8",
    "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-beta8",
    "Microsoft.Framework.Configuration.Json": "1.0.0-beta8",
    "Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta8",
    "Microsoft.Framework.Logging": "1.0.0-beta8",
    "Microsoft.Framework.Logging.Console": "1.0.0-beta8",
    "StreakMaker.Data": "1.0.0-*",
    "StreakMaker.Business": "1.0.0-*",
    "React.AspNet": "2.0.0",
    "Microsoft.AspNet.SignalR": "2.2.0",
    "EntityFramework.SqlServer": "7.0.0-beta8",
    "EntityFramework.Core": "7.0.0-beta8",
    "EntityFramework.Relational": "7.0.0-beta8",
    "Microsoft.AspNet.Mvc": "6.0.0-beta8"
  },
  "frameworks": {
    "dnx451": {
      "frameworkAssemblies": {
        "System": "4.0.0.0",
        "System.Data": "4.0.0.0",
        "System.Data.Linq": "4.0.0.0",
        "System.Collections": "4.0.0.0",
        "System.Threading": "4.0.0.0"
      }
    }
  },
  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel",
    "ef": "EntityFramework.Commands"
  },
  "exclude": [
    "wwwroot",
    "node_modules",
    "bower_components"
  ],
  "publishExclude": [
    "node_modules",
    "bower_components",
    "**.xproj",
    "**.user",
    "**.vspscc"
  ],
  "scripts": {
    "postrestore": [ "npm install" ],
    "prepare": [ "gulp copy" ]
  },
  "configurations": {
    "development": { },
    "production": { },
    "staging": { }
  }
}

Startup.cs

using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Diagnostics.Entity;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Data.Entity;
using Microsoft.Data.Entity.Internal;
using Microsoft.Dnx.Runtime;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging;
using Microsoft.Framework.Configuration;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using StreakMaker.Business;
using StreakMaker.Data.Context;
using StreakMaker.Data.Model;
using StreakMaker.Data.Repositories;
using StreakMaker.Data.Repositories.Contracts;
using React.AspNet;

namespace StreakMaker
{
    public class Startup
    {
        private readonly IConfiguration _configuration;

        public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
        {
            // Setup configuration sources.
            var configBuilder = new ConfigurationBuilder()
                .SetBasePath(appEnv.ApplicationBasePath)
                .AddJsonFile("config.json")
                .AddJsonFile($"config.{env.EnvironmentName}.json", true);

            if (env.IsEnvironment("development"))
            {
                // This reads the configuration keys from the secret store.
                // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
                configBuilder.AddUserSecrets();
            }
            configBuilder.AddEnvironmentVariables();
            _configuration = configBuilder.Build();
        }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<AppSettings>(_configuration.GetSection("AppSettings"));

            services.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<ApplicationDbContext>(options =>
                    options.UseSqlServer(_configuration["Data:DefaultConnection:ConnectionString"]));

            //using (ApplicationDbContext ctx = DbContextActivator.CreateInstance<ApplicationDbContext>(services.BuildServiceProvider()))
            //{
            //    ctx.Database.Migrate();
            //}

            services.AddIdentity<ApplicationUser, IdentityRole>()
                .AddEntityFrameworkStores<ApplicationDbContext>()
                .AddDefaultTokenProviders();

            services.AddMvc();
            services.AddTransient<IMessageService, MessageService>();
            services.AddTransient<IUserRepository, UserRepository>();
            services.AddReact();
        }

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory)
        {
            loggerfactory.AddConsole(minLevel: LogLevel.Warning);

            if (env.IsEnvironment("Development"))
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage(DatabaseErrorPageOptions.ShowAll);
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();
            app.UseIdentity();
            app.UseIISPlatformHandler();

            // For more information see http://go.microsoft.com/fwlink/?LinkID=532715
            app.UseFacebookAuthentication(options =>
            {
                options.AppId = _configuration["Authentication:Facebook:AppId"];
                options.AppSecret = _configuration["Authentication:Facebook:AppSecret"];
            });
            app.UseGoogleAuthentication(options =>
            {
                options.ClientId = _configuration["Authentication:Google:ClientId"];
                options.ClientSecret = _configuration["Authentication:Google:ClientSecret"];
            });
            app.UseMicrosoftAccountAuthentication(options =>
            {
                options.ClientId = _configuration["Authentication:MicrosoftAccount:ClientId"];
                options.ClientSecret = _configuration["Authentication:MicrosoftAccount:ClientSecret"];
            });
            app.UseTwitterAuthentication(options =>
            {
                options.ConsumerKey = _configuration["Authentication:Twitter:ConsumerKey"];
                options.ConsumerSecret = _configuration["Authentication:Twitter:ConsumerSecret"];
            });

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

                routes.MapRoute(
                    name: "streak",
                    template: "{friendlyUrl}",
                    defaults: new {controller = "Streak", action = "Detail"});

                routes.MapRoute(
                    name: "defaultApi", 
                    template: "api/{controller}/{id?}");
            });

            app.UseReact(config =>
            {
                config
                    .AddScript("~/scripts/Feed/LiveFeedForm.js")
                    .AddScript("~/scripts/Feed/LiveFeedRow.js")
                    .AddScript("~/scripts/Feed/LiveFeedList.js")
                    .AddScript("~/scripts/Common/TextInput.js");

                config.SetJsonSerializerSettings(new JsonSerializerSettings()
                {
                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                });
            });
        }
    }
}

【问题讨论】:

  • 运行 dnvm list 时选择了哪个运行时?我想知道它是否偶然指向beta7?您是否还安装了最新的网络工具以及 beta 8 安装?
  • 就像@armen.shimoon 说的,看看你项目的属性,看看是否设置了正确的 DNX 版本。此外,请确保您安装了最新版本的 DNVM 和 WebTools for Visual Studio。
  • 我知道我已经更新了 dnvm 以使用 beta8 并在项目属性中指向 beta8。我也在使用 .net 4.5.1 而不是 core,因为并非所有库都与 core(react.net、signalr)一起使用。我很确定我更新了 VS 网络工具,但我会尽快检查。
  • @RyanLangton 具体来说,您需要 WebToolsExtensionsVS14.msi,如下所示docs.asp.net/en/latest/getting-started/…
  • 我需要安装的是 WebToolsExtensionsVS14.msi。我现在可以在 IISExpress 中运行。 Kestrel 仍然给我立即错误 500。

标签: asp.net-core


【解决方案1】:

首先,确保您的项目配置为以 Beta8(项目属性)运行,并且您的 dnvm list 显示您已安装 beta8。

然后,确保您在 wwwroot\bin 中的任何位置都没有 AspNetLoader.dll

准备好了吗?

Microsoft.Dnx.Host.Clr.EntryPoint 是 ASP.NET 5 和 IIS 之间的 Helios shim (AspNetLoader.dll) 的入口点。以下是您应该做的事情:

  1. 确保Startup.cs:Configure 方法首先具有以下行:app.UseIISPlatformHandler()

  2. 确保您没有设置以下环境变量:WEBPROJ_ENABLEBETA7RENAMES

  3. 更新 global.json 以获得最新的运行时版本。

这应该会让你继续前进。如果您有不同的错误消息,请告诉我。

这是我的source

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-11
    • 2022-01-23
    • 2020-06-25
    • 2021-01-11
    • 2021-09-25
    • 1970-01-01
    • 2018-10-31
    相关资源
    最近更新 更多