![](/img/trans.png)
[英]System.TypeLoadException Microsoft.VisualBasic ASP.NET Core 2
[英]'System.TypeLoadException' occurred in > Microsoft.AspNet.Mvc.Core.dll
我正在尝试创建示例 asp.net 核心应用程序。 但是在调试时它会抛出一个错误:
Microsoft.AspNet.Mvc.Core.dll 中出现类型为“System.TypeLoadException”的异常,但未在用户代码中处理
附加信息:无法从程序集“Microsoft.Extensions.DependencyInjection.Abstractions,Version=1.0.0.0,Culture=neutral,PublicKeyToken=adb9793829ddae60”加载类型“Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionExtensions”。
怎么了?
项目.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%" ]
}
}
启动文件
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();
}
}
删除"Microsoft.AspNetCore.Mvc.Core": "1.0.1"
和"Microsoft.AspNet.Mvc": "6.0.0-rc1-final"
,然后将其替换为"Microsoft.AspNetCore.Mvc": "1.0.1"
最终版本
{
"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
已经引用了Microsoft.AspNet.Mvc.Core
,所以不需要直接引用它。
您在依赖项中缺少 "Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0"。
您的project.json
看起来像您使用的是 ASP.NET Core RC2,但从那时起您升级到了发布版本。
文档说,为了使 RC2 中的一切正常,你应该
如果您的目标是 .NET Core 和 RC2,您需要将导入添加到 project.json 作为一些不支持 .NET Standard 的 EF Core 依赖项的临时解决方法。 现在可以删除这些。
来源: ASP.NET Core 文档
所以删除
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
从你的project.json
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.