Search code examples
c#asp.net-core.net-core-rc2dotnet-cli

dotnet run - MissingMethodException


im trying to migrate RC1 project to RC2. My project restoring and building succesfuly. But when i type dotnet run i got Exception: Could not find method: 'Microsoft.Extensions.Configuration.IConfigurationBuilder Microsoft.Extensions.Configuration.IConfigurationBuilder.Add(Microsoft.Extensions.Configuration.IConfigurationProvider)'.

And this is my Startup constructor:

public Startup(IHostingEnvironment env)
    {
        Log.Logger = new LoggerConfiguration().MinimumLevel.Debug().
            WriteTo.RollingFile(@"C:\log\file-{Date}.txt",
                outputTemplate:
                    "{Timestamp: yyyy-MM-dd HH:mm:ss.fff zzz} {Level}:{EventId} [{SourceContext}] {Message}{NewLine}{Exception}")
            .CreateLogger();

        var builder = new ConfigurationBuilder() //<-error in this line
            .SetBasePath(env.ContentRootPath)
            .AddJsonFile("appsettings.json")
            .AddJsonFile("config.json")
            .AddEnvironmentVariables();

        Configuration = builder.Build();
    }

And this is my project.json:

    {
     "version": "1.0.0-*",
     "buildOptions": {
     "emitEntryPoint": true
  },
  "runtimeOptions": {
    "gcServer": false,
    "gcConcurrent": true
  },
  "dependencies": {
    "bootstrap": "4.0.0-alpha2",
    "BootstrapNotifications": "0.3.2",
    "bootstrap-notify": "0.1.0",
    "Dapper": "1.50.0-rc2",
    "Microsoft.AspNet.Antiforgery": "1.0.0-rc1-final",
    "Microsoft.AspNet.Http.Extensions": "1.0.0-rc1-final",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Http.Extensions": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.JsonPatch": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Mvc.Formatters.Json": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Mvc.Razor": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Mvc.ViewFeatures": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Server.WebListener": "0.1.0-rc2-final",
    "Microsoft.AspNetCore.Session": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
    "Microsoft.Exchange.WebServices": "2.2.0",
    "Microsoft.Extensions.Configuration.Abstractions": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.Binder": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-final",
    "Microsoft.Extensions.Primitives": "1.0.0-rc2-final",
    "Microsoft.Framework.Configuration.EnvironmentVariables": "1.0.0-beta6",
    "Microsoft.Framework.ConfigurationModel": "1.0.0-beta4",
    "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta4",
    "Microsoft.Framework.Logging": "1.0.0-beta8",
    "Microsoft.NetCore.App": {
      "type": "platform",
      "version": "1.0.0-rc2-16357"
    },
    "Microsoft.NETCore.Platforms": "1.0.1-rc2-24027",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc2-final",
    "Newtonsoft.Json": "8.0.3",
    "OctoPack": "3.0.60",
    "PagedList": "1.17.0",
    "PagedList.Mvc": "4.5.0",
    "Serilog.Extensions.Logging": "1.0.0-rc2-10104",
    "Serilog.Framework.Logging": "1.0.0-rc1-final-10083",
    "Serilog.Sinks.Literate": "2.0.0-rc-25",
    "Serilog.Sinks.RollingFile": "2.0.0-rc-703",
    "System.Console": "4.0.0-rc2-24027",
    "System.Linq": "4.1.0-rc2-24027",
    "System.Linq.Dynamic": "1.0.6",
    "System.Runtime.Extensions": "4.1.0-rc2-24027",
    "System.Xml.XmlDocument": "4.0.1-rc2-24027"
  },
  "exclude": [
    "wwwroot",
    "node_modules"
  ],
  "frameworks": {
    "net46": {
      "imports": [
        "dnxcore50",
        "portable-net45+win8"
      ],
      "dependencies": {
      }
    }
  },
  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "appsettings.json",
      "web.config"
    ]
  }
}

Solution

  • You're using mismatched versions of packages. Specifically, the exception is caused by this line:

    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc1-final",
    

    Other packages are RC2, this one is RC1. This means that AddEnvironmentVariables() is the RC1 version, and it tries to call a method from its dependency, which was changed in RC2.

    To fix this, use only RC2 packages.