升级到Asp.net beta8后无法启动应用程序

时间:2015-11-10 03:40:37

标签: asp.net-core

最近按照以下优秀说明将我的应用程序从ASP.NET beta7升级到beta8:http://wildermuth.com/2015/10/20/Upgrading_from_ASP_NET_5_Beta_7_to_Beta_8

不幸的是我仍然无法启动我的应用程序。如果我尝试使用Kestel(web)启动,我会在调试之前得到500内部服务器错误,甚至在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"
      }
    }
  }
}

project.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()
                });
            });
        }
    }
}

1 个答案:

答案 0 :(得分:1)

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

然后,请确保AspNetLoader.dll中的任何地方都没有wwwroot\bin

准备好了吗?

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以获取最新的运行时版本。

  4. 这应该让你去。如果您有其他错误消息,请告诉我。

    这是我的source