I'm having this problem: No service for type 'Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataDictionaryFactory' has been registered. In asp.net core 1.0, it seems that when the action try to render the view i have that exception.
I've searched a lot but I dont found a solution to this, if somebody can help me to figure out what's happening and how can I fix it, i will appreciate it.
My code bellow:
My project.json file
{ "dependencies": { "Microsoft.NETCore.App": { "version": "1.0.0", "type": "platform" }, "Microsoft.AspNetCore.Diagnostics": "1.0.0", "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", "Microsoft.Extensions.Logging.Console": "1.0.0", "Microsoft.AspNetCore.Mvc": "1.0.0", "Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final", "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final", "EntityFramework.Commands": "7.0.0-rc1-final" }, "tools": { "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final" }, "frameworks": { "netcoreapp1.0": { "imports": [ "dnxcore50", "portable-net45+win8" ] } }, "buildOptions": { "emitEntryPoint": true, "preserveCompilationContext": true }, "runtimeOptions": { "configProperties": { "System.GC.Server": true } }, "publishOptions": { "include": [ "wwwroot", "web.config" ] }, "scripts": { "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] } }
My Startup.cs file
using System; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using OdeToFood.Services; namespace OdeToFood { public class Startup { public IConfiguration configuration { get; set; } // This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddScoped<IRestaurantData, InMemoryRestaurantData>(); services.AddMvcCore(); services.AddSingleton(provider => configuration); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } //app.UseRuntimeInfoPage(); app.UseFileServer(); app.UseMvc(ConfigureRoutes); app.Run(async (context) => { await context.Response.WriteAsync("Hello World!"); }); } private void ConfigureRoutes(IRouteBuilder routeBuilder) { routeBuilder.MapRoute("Default", "{controller=Home}/{action=Index}/{id?}"); } } }
Solution: Use AddMvc()
instead of AddMvcCore()
in Startup.cs
and it will work.
Please see this issue for further information about why:
For most users there will be no change, and you should continue to use AddMvc() and UseMvc(...) in your startup code.
For the truly brave, there's now a configuration experience where you can start with a minimal MVC pipeline and add features to get a customized framework.
https://github.com/aspnet/Mvc/issues/2872
You might also have to add a reference toMicrosoft.AspNetCore.Mvc.ViewFeature
in project.json
https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.ViewFeatures/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With