Microsoft.AspNetCore.Hosting的System.BadImageFormatException [英] System.BadImageFormatException for Microsoft.AspNetCore.Hosting
问题描述
看来我已经设法以某种方式破坏了我计算机的.NET Core安装.我无法运行任何基本的ASP.NET Core应用程序.而是发生以下错误:
It seems I've somehow managed to corrupt my machine's .NET Core installation. I am unable to run any basic ASP.NET Core application. Instead the following error occurs:
发生System.BadImageFormatException
System.BadImageFormatException occurred
HResult = 0x80131018
HResult=0x80131018
Message =无法加载文件或程序集"Microsoft.AspNetCore.Hosting,版本= 1.1.0.0,Culture = neutral,PublicKeyToken = adb9793829ddae60".该模块应该包含一个程序集清单.
Message=Could not load file or assembly 'Microsoft.AspNetCore.Hosting, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The module was expected to contain an assembly manifest.
Source = <Cannot evaluate the exception source>
Source=<Cannot evaluate the exception source>
StackTrace: 在C:\ CoreTest2017 \ CoreTest2017 \ Program.cs:第23行的CoreTest2017.Program.Main(String [] args)中
StackTrace: at CoreTest2017.Program.Main(String[] args) in C:\CoreTest2017\CoreTest2017\Program.cs:line 23
无论我运行哪个.NET Core版本,都会发生这种情况.我还没有尝试重新安装任何东西(我在这台工作机上没有本地管理员权限...),所以我想先在这里检查是否有人遇到此问题,尤其是与ASP.NET Core有关的问题
This occurs regardless of which .NET Core version I run. I haven't tried reinstalling anything yet (I don't have local admin rights on this work machine...) so I wanted to check here first to see if anyone has encountered this issue, especially as it relates to ASP.NET Core.
为清楚起见,这是Web应用程序的标准模板. Program.cs
的内容是:
For clarity, this is a standard template for a web application. The Program.cs
contents are:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
namespace CoreTest2017
{
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseApplicationInsights()
.Build();
host.Run();
}
}
}
这是.csproj
标记(这是一个空的Web项目,以相同的方式失败):
Here is the .csproj
markup (this is for an empty web project, which fails the same way):
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.0" />
</ItemGroup>
</Project>
有人能指出我正确的方向吗?
Can anyone point me in the right direction?
推荐答案
该模块应包含一个程序集清单.
The module was expected to contain an assembly manifest.
当您混合使用x86/x64位时,可能会发生这种情况.但是由于有问题的程序集是Microsoft.AspNetCore.Hosting,所以我怀疑问题是您的NuGet缓存某种程度上已损坏.尝试删除%USERPROFILE%.nuget \ packages \ Microsoft.AspNetCore.Hosting"并重新运行还原.
This can happen when you are mixing x86/x64 bits. But as the assembly in question is Microsoft.AspNetCore.Hosting, I suspect the problem is that your NuGet cache is corrupted somehow. Try deleting the "%USERPROFILE%.nuget\packages\Microsoft.AspNetCore.Hosting" and rerunning restore.
如果仍然遇到该错误,则可能需要调试主机,以找出它要加载的程序集.将环境变量COREHOST_TRACE设置为1并运行您的应用程序.这将产生有关您的应用尝试加载的程序集的详细信息.
If you still encounter the error, you may need to debug the host to figure out which assembly it is trying to load. Set the environment variable COREHOST_TRACE to 1 and run your app. This will produce detailed info on which assemblies your app is trying to load.
这篇关于Microsoft.AspNetCore.Hosting的System.BadImageFormatException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!