ASP.NET Core System.TypeLoadException DependencyInjection.Extensions.ServiceCollectionExtensions错误
我是Asp.Net Core的新手。在创建一个简单的MVC项目时,我遇到了以下错误。ASP.NET Core System.TypeLoadException DependencyInjection.Extensions.ServiceCollectionExtensions错误
System.TypeLoadException未能加载类型 'Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionExtensions' 从程序集“Microsoft.Extensions.DependencyInjection.Abstractions, 版本= 1.0.0.0,文化=中性公钥= adb9793829ddae60' 。在 Microsoft.Extensions.DependencyInjection.OptionsServiceCollectionExtensions.AddOptions(IServiceCollection 服务)在 Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.AddMvcCore(IServiceCollection 服务,行动setupAction)在 Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddMvc(IServiceCollection 服务,动作setupAction)在 POC.Startup.ConfigureServices(IServiceCollection服务)
System.Reflection.TargetInvocationException 异常已通过调用的目标引发异常 。在 System.RuntimeMethodHandle.InvokeMethod(对象目标,对象[] 参数,签名Sig,布尔构造函数)在 System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(obj对象, 对象[]参数,对象[]参数)在 系统.Reflection.RuntimeMethodInfo.Invoke在 微软(obj对象,的BindingFlags invokeAttr,粘结剂粘结剂,对象[]参数,CultureInfo的培养物) 在 Microsoft.AspNetCore.Hosting.Internal.ConfigureServicesBuilder.Invoke(对象 例如,IServiceCollection exportServices) .AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices() at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
以下是我Project.json文件
{
"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.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel":"1.0.0-rc1-final",
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
"Microsoft.AspNet.Mvc.Core": "6.0.0-rc1-final"
},
"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文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.DependencyInjection;
namespace POC
{
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)
{
app.UseMvc(m=>
m.MapRoute(
name:"Default",
template:"{controller}/{action}/{id?}",
defaults:new { controller="Home", action="index"}
));
}
}
}
我在启动时service.AddMvc()线得到错误。 cs文件 请为此建议一个解决方案。
您是否尝试过使用这种依赖对MVC在project.json:
"Microsoft.AspNetCore.Mvc": "1.0.0"
,而不是这些?
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
"Microsoft.AspNet.Mvc.Core": "6.0.0-rc1-final"
这有可能是使用AspNetCore
与AspNet
为你的MVC的依赖导致冲突。
是的,这导致了我的冲突。谢谢 –