2017-08-12 119 views
4

創建主機變量時,此例外出現在Program.cs中,我沒有更新Program.cs中的任何內容,因此我不知道它出現的原因。 我試過重新啓動VS並刪除了解決方案中的所有項目中的bin和obj。Program.cs中的System.MissingMethodException

異常

未找到方法: 'System.Collections.Generic.Dictionary`2 Microsoft.Extensions.Configuration.IConfigurationBuilder.get_Properties()'。

的Program.cs

using Microsoft.AspNetCore.Hosting; 
using System.IO; 

namespace LC.Smokers 
{ 
    public class Program 
    { 
     public static void Main(string[] args) 
     { 
      var host = new WebHostBuilder() 
       .UseKestrel() 
       .UseContentRoot(Directory.GetCurrentDirectory()) 
       .UseIISIntegration() 
       .UseStartup<Startup>() 
       .UseApplicationInsights() 
       .Build(); 

      host.Run(); 
     } 
    } 
} 

Startup.cs

public class Startup 
{ 
    public Startup(IHostingEnvironment env) 
    { 
     var builder = new ConfigurationBuilder() 
      .SetBasePath(env.ContentRootPath) 
      .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) 
      .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) 
      .AddEnvironmentVariables(); 
     Configuration = builder.Build(); 
    } 

    public IConfigurationRoot Configuration { get; } 

    public void ConfigureServices(IServiceCollection services) 
    { 
     services.AddLocalization(options => options.ResourcesPath = "Resources"); 

     services.AddSingleton<IActionContextAccessor, Models.ActionContextAccessor>(); 
     services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); 
     services.AddSingleton<AppHelper>(); 
     services.AddTransient<SessionHelper>(); 

     services.AddDistributedMemoryCache(); 

     services.AddSession(options => 
     { 
      options.Cookie.Name = ".Smokers.Session"; 
      options.IdleTimeout = TimeSpan.FromHours(2); 
     }); 

     services.AddMvc() 
      .AddViewLocalization(Microsoft.AspNetCore.Mvc.Razor.LanguageViewLocationExpanderFormat.Suffix) 
      .AddDataAnnotationsLocalization(); 
    } 

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 
    { 
     loggerFactory.AddConsole(Configuration.GetSection("Logging")); 
     loggerFactory.AddDebug(); 

     if (env.IsDevelopment()) 
     { 
      app.UseDeveloperExceptionPage(); 
      app.UseBrowserLink(); 
     } 
     else 
     { 
      app.UseExceptionHandler("/Shop/Error"); 
     } 

     List<CultureInfo> supportedCultures = new List<CultureInfo> 
     { 
      new CultureInfo("no-NB"), 
      new CultureInfo("en-US") 
     }; 

     app.UseRequestLocalization(new RequestLocalizationOptions 
     { 
      DefaultRequestCulture = new RequestCulture("no-NB"), 
      SupportedCultures = supportedCultures, 
      SupportedUICultures = supportedCultures 
     }); 

     app.UseSession(); 
     app.UseStaticFiles(); 

     app.UseMvc(routes => 
     { 
      routes.MapRoute(
       name: "default", 
       template: "{controller=Shop}/{action=Index}/{id?}"); 
     }); 
    } 
} 
+0

[Signalr Core for ASP.net core 2.0無法正常工作,無論我嘗試]的可能的重複(https://stackoverflow.com/questions/45497003/signalr-core-for-asp-net-core-2- 0-not-working-no-matter-what-i-try) – mjwills

回答

1

原來這是與使用的版本Microsoft.AspNetCore.Session包的問題2.0.0和該項目的其餘部分使用2.0.0預覽2最後。

我降級了軟件包,它工作。

+0

爲了增加這個答案,我需要降級一些我用來預覽2最終的其他軟件包(即Microsoft.Extensions.Options) 。一旦我的所有版本匹配,我就能夠再次運行我的應用程序。 – SlackerCoder

相關問題