dotnet run - MissingMethodException

时间:2016-05-23 13:49:13

标签: c# asp.net-core .net-core-rc2 dotnet-cli

我试图将RC1项目迁移到RC2。我的项目恢复和建设成功。但是当我键入dotnet run时,我得到了Exception:找不到方法:&#39; Microsoft.Extensions.Configuration.IConfigurationBuilder Microsoft.Extensions.Configuration.IConfigurationBuilder.Add(Microsoft.Extensions.Configuration.IConfigurationProvider)&#39;。< / p>

这是我的Startup构造函数:

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

这是我的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"
    ]
  }
}

2 个答案:

答案 0 :(得分:3)

您正在使用不匹配的软件包版本。具体来说,异常是由这一行引起的:

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

其他包是RC2,这个是RC1。这意味着AddEnvironmentVariables()是RC1版本,它尝试从其依赖项调用方法,该方法在RC2中已更改。

要解决此问题,请仅使用RC2包。

答案 1 :(得分:0)

解决方案与svick的回答密切相关。

我做了一个干净的重建,错误被清除了......