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=<无法评估异常源>
堆栈跟踪:在 CoreTest2017.Program.Main(String[] args) 在 C:CoreTest2017CoreTest2017Program.cs:line 23
StackTrace: at CoreTest2017.Program.Main(String[] args) in C:CoreTest2017CoreTest2017Program.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%.nugetpackagesMicrosoft.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%.nugetpackagesMicrosoft.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屋!