8

This exception just appeared in Program.cs when creating the host variable, I didn't update anything in Program.cs so I don't know why it appears. I've tried restarting VS and deleted bin and obj in all projects in the solution.

Exception:

Method not found: '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?}");
        });
    }
}
1

2 Answers 2

2

Turns out it was an issue with the Microsoft.AspNetCore.Session package that was using version 2.0.0 and the rest of the project is using 2.0.0 preview 2 final.

I downgraded the package and it worked.

Sign up to request clarification or add additional context in comments.

1 Comment

Just to add to this answer, I needed to downgrade a few of the other packages I was using to preview 2 final (ie. Microsoft.Extensions.Options). Once I had all my versions matching, I was able to run my app again.
0

In case anyone else has this problem more recently... I added a ref to IMemoryCache and intellisense suggested loading the latest NuGet package. I accepted the suggestion and then ran my Azure .NetCore 3.1 function application. It threw the same exception in StartUp.cs. Turns out the latest (v5.0) works with FF 4.61 and Standard library 2.0. I downgraded to version 3.1.19 and everything worked fine.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.