11

I have followed the steps here to upgrade from ASP.NET 5 Beta 4 to Beta 5 but am getting an error at runtime when calling application.UseBrowserLink();:

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

Additional information: Could not load type 'Microsoft.AspNet.Builder.IApplicationBuilder' from assembly 'Microsoft.AspNet.Http, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

These are the steps I followed:

  1. Had VS 2015 RC already installed.
  2. From PowerShell run: $env:DNX_FEED="https://www.nuget.org/api/v2"
  3. From PowerShell run: dnvm upgrade
  4. Added a Global.json file (I did not already have one). When I added it, it referred to Beta 5 already:

    {
        "projects": [ "Source", "Tests" ],
        "sdk": {
            "version": "1.0.0-beta5-12103"
        }
    }
    
  5. Updated all packages in project.json to Beta 5. You can see a full version of my project.lock.json file here.

    {
      "dependencies": {
        "Boilerplate.Web.Mvc6": "1.0.2",
        "Microsoft.AspNet.Diagnostics": "1.0.0-beta5",
        "Microsoft.AspNet.Mvc": "6.0.0-beta5",
        "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta5",
        "Microsoft.AspNet.Mvc.Xml": "6.0.0-beta5",
        "Microsoft.AspNet.Server.IIS": "1.0.0-beta5",
        "Microsoft.AspNet.Server.WebListener": "1.0.0-beta5",
        "Microsoft.AspNet.StaticFiles": "1.0.0-beta5",
        "Microsoft.AspNet.Tooling.Razor": "1.0.0-beta5",
        "Microsoft.Framework.CodeGenerators.Mvc": "1.0.0-beta5",
        "Microsoft.Framework.Configuration.EnvironmentVariables": "1.0.0-beta5",
        "Microsoft.Framework.Configuration.Json": "1.0.0-beta5",
        "Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta5",
        "Microsoft.Framework.Logging": "1.0.0-beta5",
        "Microsoft.Framework.Logging.Console": "1.0.0-beta5",
        "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta5",
        "Newtonsoft.Json": "6.0.6",
        "System.Runtime": "4.0.20-beta-23019"
      }
      "frameworks": {
          "dnx451": {
            "frameworkAssemblies": {
              "System.Net.Http": "4.0.0.0",
              "System.ServiceModel": "4.0.0.0"
            }
          },
          "dnxcore50": {
            "dependencies": {
              "System.Net.Http": "4.0.0-beta-23019"
            }
          }
        }
    }
    
  6. The instructions then go on to say you should run the following commands but I believe VS 2015 RC does this for you dnu restore then dnu build.

UPDATE

It seems to be a problem with browser link, commenting the line out allows the site to work. It may be broken? Need to hunt around the aspnet GitHub issues.

Muhammad Rehan Saeed
  • 35,627
  • 39
  • 202
  • 311

6 Answers6

21

In order to help you migrate from beta4 to beta5, these are the following steps it took me, based on the research/findings.

Environment

  • PowerShell run: $env:DNX_FEED="https://www.nuget.org/api/v2"
  • PowerShell run: dnvm install 1.0.0-beta5
  • PowerShell run: dnvm use 1.0.0-beta5 -p (not sure if its needed however i had to)

Project

  • Open global.json and update sdk to 1.0.0-beta5 should look like this:

    {
        "projects": [ "src", "test" ],
        "sdk": {
            "version": "1.0.0-beta5"
        }
    }
    
  • Open project.json:

    • Updated dependencies versions from beta4 to beta5
    • Change Configuration dependency from:

      "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta4"
      

      to

      "Microsoft.Framework.Configuration": "1.0.0-beta5",
      "Microsoft.Framework.Configuration.Json": "1.0.0-beta5"
      
    • Remove Microsoft.VisualStudio.Web.BrowserLink.Loader
    • Rename _GlobalImport.cshtml to _ViewImports.cshtml

Startup.cs changes

  • Change Configuration breaking changes

    • Change namespace from using Microsoft.Framework.ConfigurationModel; to using Microsoft.Framework.Configuration;

    • Change Configuration.GetSubKey to Configuration.GetConfigurationSection

    • Change CTOR to:

      public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
      {           
          // Setup configuration sources.
          var configBuilder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
          .AddJsonFile("config.json")
          .AddEnvironmentVariables();
      
          Configuration = configBuilder.Build();
      }
      
    • Remove app.UseBrowserLink();

Project DNU CMDs

  • Open PowerShell within app root
  • Run dnu restore
  • Run dnu build
  • Closing and reopening VS at this point helps sometimes.

Myself found it quite difficult to upgrade an existing project, couldn't find all steps required all together. Hope it helps!

Ryan Langton
  • 6,294
  • 15
  • 53
  • 103
Stephen Lautier
  • 3,065
  • 3
  • 17
  • 20
  • If you could update your experience for beta 6. That would be appreciated. – hlyates Jul 29 '15 at 19:09
  • Excellent info and research, thanks. MS have seriously dropped the ball with VS2015... and sadly with everything in their post Win-7 era :( – nathanchere Aug 13 '15 at 08:35
5

To complete, if you want to update from beta 4 to beta 6, see the Stephen Lautier's answer and to this after :

To update from beta 5 to beta 6 :

I did :

  • Open global.json and update sdk to "1.0.0-beta6" and save this file
  • Visual Studio 2015 proposes to download beta6, click on Yes

In project.json :

  • change dnx451 (or dnx452) to dnx46 (To use Framework 4.6)
  • replace all "-beta5" with "-beta6" in this file
  • remove Microsoft.Framework.ConfigurationModel.UserSecrets

In Startup.cs, if you use Session :

  • replace app.UseInMemorySession(...) with app.UseSession()
  • In ConfigureServices, add this :

     services.AddCaching();
     services.AddSession();
     services.ConfigureSession(o => {    o.IdleTimeout = TimeSpan.FromSeconds(10); });
    
  • Right click on your Project > Properties > Debug > Add a new Environment Variable :

Name : DNX_IIS_RUNTIME_FRAMEWORK

Value : dnx46

See that for more information : http://jameschambers.com/2015/07/launching-an-asp-net-5-application-from-visual-studio-2015/

  • In Package Manager Console, write this "dnu restore" and this "dnu build"
  • Restart Visual Studio

My project work in beta6 after that, maybe there are other things to do.

orrel
  • 248
  • 2
  • 6
2

After speaking with @davidfowl from the ASP.NET vNext team, he told me that Browser Link doesn't work in beta5 and should be removed.

radu-matei
  • 3,469
  • 1
  • 29
  • 47
1

Microsoft.AspNet.Http and Microsoft.AspNet.Http.Core package names swapped

Victor Hurdugaci
  • 28,177
  • 5
  • 87
  • 103
1

This is the thing:

You updated the DNX from beta4 to beta5, and you want to run an MVC6 template inside Visual Studio RC (whose templates were built around beta4).

In the first place, "Microsoft.Framework.Configuration.Json" doesn't exist in beta5 anymore. (you should definitely see this: https://github.com/aspnet/announcements/issues?q=milestone%3A1.0.0-beta5 - breaking changes from beta4 to beta5).

In order to see that your DNX was updated properly, build a new empty web project and simply add MVC/WebAPI (simple cases to check that it works).

I haven't tried to run the MVC template yet, but I will try and come back to you.

radu-matei
  • 3,469
  • 1
  • 29
  • 47
  • "Microsoft.Framework.ConfigurationModel.Json" was renamed to "Microsoft.Framework.Configuration.Json". It does exist. – Muhammad Rehan Saeed Jul 07 '15 at 09:09
  • Yes, you are right. :) Have you succeeded in running the template? – radu-matei Jul 07 '15 at 09:22
  • Btw, You should try the MVC6 template without authentication, as EF has suffered some changes: https://github.com/aspnet/Announcements/issues/35 – radu-matei Jul 07 '15 at 09:24
  • Not using EF. The template runs fine after commenting out the browser link line. – Muhammad Rehan Saeed Jul 07 '15 at 09:32
  • Ok, I got in contact with @davidfowl from the ASP.NET vNext team and he told me that BrowserLink is broken in beta5 and I should remove it – radu-matei Jul 07 '15 at 10:39
  • 2
    If you want to play around with the new beta5, install Yeoman which gives you basic templates for webapps, including the mvc template (including EF) – radu-matei Jul 09 '15 at 07:24
  • Where can I find the GitHub page for those project templates? – Muhammad Rehan Saeed Jul 09 '15 at 07:25
  • 1
    The best thing you can do is install Node (if you don't have it already) and install Yeoman for asp.net 5, then you can create functional beta 5 templates (MVC Web App, Web App without authentication etc). I haven't found them on GitHub so far. – radu-matei Jul 14 '15 at 10:58
1

In case anyone is wondering how to update to ASP.NET 5 Beta 7, I found it useful to download the latest ASP.NET and Web Tools updates for Visual Studio 2015 and then create a new ASP.NET 5 project in Visual Studio.

This will create a Beta 7 project with the project structure, code and referenced dependencies for you. You can then use this as a guide to upgrade any existing older Beta projects.

For example here what my project.json looks like using all the Beta 7 dependencies:

{
  "webroot": "wwwroot",
  "userSecretsId": "aspnet5-WebApplication1-a433a0ef-3bed-4bc9-8086-8d18070fa2c1",
  "version": "1.0.0-*",

  "dependencies": {
    "EntityFramework.Commands": "7.0.0-beta7",
    "EntityFramework.SqlServer": "7.0.0-beta7",
    "Microsoft.AspNet.Authentication.Cookies": "1.0.0-beta7",
    "Microsoft.AspNet.Authentication.Facebook": "1.0.0-beta7",
    "Microsoft.AspNet.Authentication.Google": "1.0.0-beta7",
    "Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-beta7",
    "Microsoft.AspNet.Authentication.Twitter": "1.0.0-beta7",
    "Microsoft.AspNet.Diagnostics": "1.0.0-beta7",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta7",
    "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta7",
    "Microsoft.AspNet.Mvc": "6.0.0-beta7",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta7",
    "Microsoft.AspNet.Server.IIS": "1.0.0-beta7",
    "Microsoft.AspNet.Server.WebListener": "1.0.0-beta7",
    "Microsoft.AspNet.StaticFiles": "1.0.0-beta7",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-beta7",
    "Microsoft.Framework.Configuration.Abstractions": "1.0.0-beta7",
    "Microsoft.Framework.Configuration.Json": "1.0.0-beta7",
    "Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta7",
    "Microsoft.Framework.Logging": "1.0.0-beta7",
    "Microsoft.Framework.Logging.Console": "1.0.0-beta7",
    "Microsoft.Framework.Logging.Debug" : "1.0.0-beta7",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta7"
  },

  "commands": {
    "web": "Microsoft.AspNet.Hosting --config hosting.ini",
    "ef": "EntityFramework.Commands"
  },

  "frameworks": {
    "dnx451": { },
    "dnxcore50": { }
  },

  "exclude": [
    "wwwroot",
    "node_modules",
    "bower_components"
  ],
  "publishExclude": [
    "node_modules",
    "bower_components",
    "**.xproj",
    "**.user",
    "**.vspscc"
  ],
  "scripts": {
    "prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
  }
}

At the time of writing, this is where you can download the beta 7 updates for Visual Studio. Ensure you get the file WebToolsExtensionsVS14.msi.

Find more information about this Beta 7 release see the blog post Announcing Availability of ASP.NET 5 Beta7

neodymium
  • 3,686
  • 6
  • 23
  • 31