Reputation: 4733
I'm trying to create sample asp.net core application. But on debug it throws an error:
An exception of type 'System.TypeLoadException' occurred in Microsoft.AspNet.Mvc.Core.dll but was not handled in user code
Additional information: Could not load type 'Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionExtensions' from assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
what's wrong?
project.json
{
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Mvc.Core": "1.0.1",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.NETCore.App": {
"version": "1.0.1",
"type": "platform"
}
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"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%" ]
}
}
Startup.cs
public class Startup
{
// 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.AddMvc();
}
// 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)
{
loggerFactory.AddConsole();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseStaticFiles();
app.UseMvc();
}
}
Upvotes: 2
Views: 3017
Reputation: 64288
Remove "Microsoft.AspNetCore.Mvc.Core": "1.0.1"
and "Microsoft.AspNet.Mvc": "6.0.0-rc1-final"
, then replace it with "Microsoft.AspNetCore.Mvc": "1.0.1"
Final version
{
"dependencies": {
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.1",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.NETCore.App": {
"version": "1.0.1",
"type": "platform"
}
}
Microsoft.AspNet.Mvc
already references Microsoft.AspNet.Mvc.Core
, so there is no need to reference it directly.
Upvotes: 1
Reputation: 1180
Your project.json
looks like you were using ASP.NET Core RC2, but since then you upgraded to released version.
Documentation says, that in order to make everything work in RC2 you were supposed to
If you were targeting .NET Core with RC2, you needed to add imports to project.json as a temporary workaround for some of EF Core’s dependencies not supporting .NET Standard. These can now be removed.
Source: ASP.NET Core documentation
So remove
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
from your project.json
Upvotes: 0
Reputation: 53
You are missing "Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0" in dependencies.
Upvotes: 0