【发布时间】:2017-01-15 01:15:42
【问题描述】:
我是 Asp.Net Core 的新手。在创建一个简单的 MVC 项目时出现以下错误。
System.TypeLoadException 无法加载类型 'Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionExtensions' 从程序集'Microsoft.Extensions.DependencyInjection.Abstractions, 版本=1.0.0.0,文化=中性,PublicKeyToken=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, Object[] 参数,Object[] 参数)在 System.Reflection.RuntimeMethodInfo.Invoke(对象 obj,BindingFlags invokeAttr、Binder binder、Object[] 参数、CultureInfo 文化) 在 Microsoft.AspNetCore.Hosting.Internal.ConfigureServicesBuilder.Invoke(对象 例如,IServiceCollection exportServices) 在 Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices() 在 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"}
));
}
}
}
我确实在 startup.cs 文件中的 service.AddMvc() 行收到错误。
请为此提出解决方案。
【问题讨论】:
标签: asp.net-core