2

Using VS 2015 with beta 7 of MVC 6 I am having issues getting Session configured for use in my web application.

When I create a new ASP.NET Web Application project I choose the Web Application ASP.NET 5 Preview Template.

I then edited the Startup.cs by adding the following line:

services.AddCaching();

I then added the following line:

services.AddSession();

At that point the editor prompted me to add a reference to this depencency:

"Microsoft.AspNet.Session": "1.0.0-beta8"

After doing so I get the following errors:

Error   CS7069  Reference to type 'IConfigurationProvider' claims it is defined in 'Microsoft.Framework.Configuration.Abstractions', but it could not be found  WebApplication1.DNX 4.5.1   c:\users\texasmike\documents\visual studio 2015\Projects\SessionTesting\src\WebApplication1\Startup.cs  29

Error   CS7069  Reference to type 'IConfigurationProvider' claims it is defined in 'Microsoft.Framework.Configuration.Abstractions', but it could not be found  WebApplication1.DNX Core 5.0    c:\users\texasmike\documents\visual studio 2015\Projects\SessionTesting\src\WebApplication1\Startup.cs  29

I have attempted a thorough search but haven't found any answers.

Here is the complete Startup.cs:

using Microsoft.AspNet.Authentication.Facebook;
using Microsoft.AspNet.Authentication.MicrosoftAccount;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Diagnostics.Entity;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Data.Entity;
using Microsoft.Dnx.Runtime;
using Microsoft.Framework.Configuration;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging;
using WebApplication1.Models;
using WebApplication1.Services;

namespace WebApplication1
{
    public class Startup
    {
        public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
        {
            // Setup configuration sources.

            var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
                .AddJsonFile("config.json")
                .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);

            if (env.IsDevelopment())
            {
                // 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
                builder.AddUserSecrets();
            }
            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
        }

        public IConfigurationRoot Configuration { get; set; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add Entity Framework services to the services container.
            services.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<ApplicationDbContext>(options =>
                    options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));

            // Add Identity services to the services container.
            services.AddIdentity<ApplicationUser, IdentityRole>()
                .AddEntityFrameworkStores<ApplicationDbContext>()
                .AddDefaultTokenProviders();

            // Configure the options for the authentication middleware.
            // You can add options for Google, Twitter and other middleware as shown below.
            // For more information see http://go.microsoft.com/fwlink/?LinkID=532715
            services.Configure<FacebookAuthenticationOptions>(options =>
            {
                options.AppId = Configuration["Authentication:Facebook:AppId"];
                options.AppSecret = Configuration["Authentication:Facebook:AppSecret"];
            });

            services.Configure<MicrosoftAccountAuthenticationOptions>(options =>
            {
                options.ClientId = Configuration["Authentication:MicrosoftAccount:ClientId"];
                options.ClientSecret = Configuration["Authentication:MicrosoftAccount:ClientSecret"];
            });

            // Add MVC services to the services container.
            services.AddMvc();

            // Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
            // You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
            // services.AddWebApiConventions();

            // Register application services.
            services.AddTransient<IEmailSender, AuthMessageSender>();
            services.AddTransient<ISmsSender, AuthMessageSender>();

            // Caching
            services.AddCaching();

            // Session
            services.AddSession();
        }

        // Configure is called after ConfigureServices is called.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.MinimumLevel = LogLevel.Information;
            loggerFactory.AddConsole();
            loggerFactory.AddDebug();

            // Configure the HTTP request pipeline.

            // Add the following to the request pipeline only in development environment.
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseErrorPage();
                app.UseDatabaseErrorPage(DatabaseErrorPageOptions.ShowAll);
            }
            else
            {
                // Add Error handling middleware which catches all application specific errors and
                // sends the request to the following path or controller action.
                app.UseErrorHandler("/Home/Error");
            }

            // Add static files to the request pipeline.
            app.UseStaticFiles();

            // Add cookie-based authentication to the request pipeline.
            app.UseIdentity();

            // Add authentication middleware to the request pipeline. You can configure options such as Id and Secret in the ConfigureServices method.
            // For more information see http://go.microsoft.com/fwlink/?LinkID=532715
            // app.UseFacebookAuthentication();
            // app.UseGoogleAuthentication();
            // app.UseMicrosoftAccountAuthentication();
            // app.UseTwitterAuthentication();

            // Add MVC to the request pipeline.
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");

                // Uncomment the following line to add a route for porting Web API 2 controllers.
                // routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}");
            });
        }
    }
}

Here is the complete project.json:

{
  "webroot": "wwwroot",
  "userSecretsId": "aspnet5-WebApplication1-36d27e1d-a781-4628-91dc-8a80cb46fd14",
  "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.Session": "1.0.0-beta8",
    "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" ]
  }
}
user4881
  • 21
  • 1
  • Please note that I made no changes to the project other than the ones mentioned in my OP in order to isolate the issue. Thanks. – user4881 Oct 15 '15 at 23:48
  • 1
    Did you try using "Microsoft.AspNet.Session": "1.0.0-beta7"? – smulholland2 Oct 16 '15 at 08:58
  • 1
    If you use beta8 in Session, you should probably use beta8 in all project dependencies. – Marcin Zablocki Oct 16 '15 at 10:27
  • As of yesterday I am having the same issue. Im using beta8 for all dependencies. That said...I think the answer lies here: https://github.com/aspnet/Configuration/commit/ff1dc034ef9e376b684194ce4193af7049d98542 where they state they are changing/have changed the library. – HendPro12 Oct 16 '15 at 13:42
  • My project.json cannot find a Microsoft.Extensions though... – HendPro12 Oct 16 '15 at 13:51
  • Thank you all for your suggestions. I tried to update all dependencies to beta8 but not all are available (e.g. Microsoft.AspNet.Server.IIS). I then tried selectively to update any that had a valid beta8 version and the default project now has 134 errors. I will proceed with using MVC4 instead. – user4881 Oct 16 '15 at 18:03
  • @user4881 dont give up. I was able to solve the same issue via answers to my post: http://stackoverflow.com/questions/33173372/asp-net5-startup-cs-configurationbuilder See the link provided in the comment from Andy Korneyev – HendPro12 Oct 16 '15 at 19:40
  • @HendPro12 Thanks for the words of encouragement. But I need to get this project finished shortly and I was hoping to use the latest version of MVC but I think it is too bleeding edge for me right now. I have created an MVC5 project and all is well now. Will look into MVC6 in the coming months. – user4881 Oct 16 '15 at 22:51

0 Answers0