Error: No service for type 'ITempDataDictionaryFactory' has been registered

Dung Do Tien Dec 19 2020 1540

After convert project Core version 2.1 to 3.1 when running web application I got an error InvalidOperationException: No service for type 'Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataDictionaryFactory' has been registered.

Below is the code of Startup.cs file:

public class Startup
    public Startup(Microsoft.AspNetCore.Hosting.IHostingEnvironment evm)
        var builder = new ConfigurationBuilder()
           .AddJsonFile("appsettings.json", true, true)
           .AddJsonFile($"appsettings.{evm.EnvironmentName}.json", true)

        Configuration = builder.Build();

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
        services.Configure<CookiePolicyOptions>(options =>
            // This lambda determines whether user consent for non-essential cookies is needed for a given request.
            options.CheckConsentNeeded = context => true;
            options.MinimumSameSitePolicy = Microsoft.AspNetCore.Http.SameSiteMode.None;


        services.AddControllers(x => x.AllowEmptyInputInBodyModelBinding = true);

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        if (env.IsDevelopment())
            // The default HSTS value is 30 days. You may want to change this for production scenarios, see




        app.UseEndpoints(routes =>
                name: "default",
                pattern: "{controller=Admin}/{action=Login}/{id?}");

Thank you for any suggestion.

Have 1 answer(s) found.
  • M

    Manish Kumar Dec 19 2020

    I got the same error In core 3.1. Add command below at the end of ConfigureServices() method, it will work for you: 


    Hope it's helpful for you.

Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close