3

Using VS 2015 with beta 8 of MVC, I receive the following error

"Severity   Code    Description Project File    Line
Error   CS1503  Argument 1: cannot convert from 'string' to 'Microsoft.Framework.Configuration.IConfigurationProvider'  NewInventory.DNX Core 5.0   F:\Projects\NewInventory\src\NewInventory\Startup.cs    35

from this portion of my startup.cs:

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

When I hover over ConfigurationBuilder I can see its looking for'ConfigurationBuilder.ConfigurationBuilder(params IConfigurationProvider[] providers)'

How do I change the appEnv.ApplicationBasePath to an IConfigurationProvider array?

my project.json is:

{
  "webroot": "wwwroot",
  "userSecretsId": "aspnet5-NewInventory-f5a8bab7-e95b-485b-97e9-9a072438b107",
  "version": "1.0.0-*",

  "dependencies": {
    "EntityFramework.SqlServer":"7.0.0-beta5",
    "EntityFramework.Commands": "7.0.0-beta5",
    "Microsoft.AspNet.Mvc": "6.0.0-beta8",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta5",
    "Microsoft.AspNet.Authentication.Cookies": "1.0.0-beta5",
    "Microsoft.AspNet.Authentication.Facebook": "1.0.0-beta5",
    "Microsoft.AspNet.Authentication.Google": "1.0.0-beta5",
    "Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-beta5",
    "Microsoft.AspNet.Authentication.Twitter": "1.0.0-beta5",
    "Microsoft.AspNet.Diagnostics": "1.0.0-beta5",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta5",
    "Microsoft.AspNet.Identity.EntityFramework":"3.0.0-beta8",
    "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.Configuration": "1.0.0-beta8",
    "Microsoft.Framework.Configuration.Abstractions": "1.0.0-beta8",
    "Microsoft.Framework.Configuration.Binder": "1.0.0-beta8",
    "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"
  },

  "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" ]
  },
  "configurations": {
  }
}
HendPro12
  • 1,094
  • 3
  • 17
  • 50
  • 2
    I knew this question would come, that's why I Q&A'd it. Beside that: you are mixing beta5 and beta8 packages, you should not do that. Update everything to beta8. – Henk Mollema Oct 16 '15 at 14:53
  • @Henk Mollema Thanks Henk. Please see my comment below about my attempt to update all to beta8 – HendPro12 Oct 16 '15 at 15:17
  • Some packages are renamed. See the [announcements repo](https://github.com/aspnet/Announcements/issues) for more info. – Henk Mollema Oct 16 '15 at 15:18

1 Answers1

8

There is no more constructor of ConfigurationBuilder having appEnv.ApplicationBasePath as argument, but instead there is SetBasePath method.

So change your code to:

var builder = new ConfigurationBuilder()
                .SetBasePath(appEnv.ApplicationBasePath)
                .AddJsonFile("config.json")
                .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);
Andrey Korneyev
  • 26,353
  • 15
  • 70
  • 71
  • 1
    Thanks Andy. Its telling me that ConfigurationBuilder does not contain a defintion for SetBasePath – HendPro12 Oct 16 '15 at 14:52
  • @HendPro12 As per your `project.json`: you're mixing beta5 and beta8 packages. This doesn't seems like a good idea, try to change everything to beta8. – Andrey Korneyev Oct 16 '15 at 14:54
  • Maybe Im doing something wrong..still learning this new method of project.json instead of the old Nuget way. However, I went through the file yesterday and used intellisense to identify the newest versions. Those without a beta 8 didnt appear to have one. – HendPro12 Oct 16 '15 at 15:13
  • @HendPro12, well looking at your packages list I can say that most of these packages has beta8 now. As Henk Mollema mentioned in comments, some packages was renamed. Also there is changes in beta8 concerning IIS hosting implementation, see [this blog article](http://blogs.msdn.com/b/webdev/archive/2015/10/15/announcing-availability-of-asp-net-5-beta8.aspx) for details. – Andrey Korneyev Oct 16 '15 at 15:30
  • Thanks Andy and Henk As an example, I can see that Microsoft.Frameworks has been changed to Microsoft.Extensions. However, when I type Microsoft.Extensions into project.json it doesnt recognize it. Can you help me to understand what Im doing wrong? – HendPro12 Oct 16 '15 at 15:38
  • 3
    @HendPro12 Actually, Microsoft.Frameworks has not been changed to Microsoft.Extensions in beta8. This change happens in github sources of ASP.NET vNext, but was not included in beta8. I suppose, this will happen in RC1 version. As a quickstart to migration from beta5 you can download Visual studio beta 8 tools from [here](http://www.microsoft.com/en-us/download/details.aspx?id=49442), then create new project using it and look for changes. – Andrey Korneyev Oct 16 '15 at 15:41
  • When did they update it ? – Nameismy Oct 27 '15 at 17:44
  • I have this problem as well. How did you fix it? It says that the ConfigurationBuilder doesn't contain a setBasePath. I can't get it working with the Microsoft.Framework.Configuration just with the Extension?? – Tom el Safadi Dec 30 '15 at 02:51
  • @Anokrize what is your ASP.NET version? Is it beta8 (as it was common at the moment of original question and my answer) or maybe it is rc1 or something else? ASP.NET 5 is still in pre-release, so things may change significantly from one build-version to another. – Andrey Korneyev Dec 30 '15 at 08:04
  • 2
    Ahh I checked it and I am using ASP.NET 5 and it is rc1. I think it changed so I have to add the `Microsoft.Extensions.Configuratio` but then it doesn't know about the IApplicationEnviroment which I need for my basepath do you know something what I could do? – Tom el Safadi Dec 30 '15 at 12:22