System.BadImageFormatException for Microsoft.AspNetCore.Hosting

2

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 occurred

HResult=0x80131018

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>

StackTrace: at CoreTest2017.Program.Main(String[] args) in C:\CoreTest2017\CoreTest2017\Program.cs:line 23

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.

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();
        }
    }
}

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?

c#
.net
iis
asp.net-core
.net-core
asked on Stack Overflow Feb 23, 2017 by Zach Becknell • edited Feb 23, 2017 by Zach Becknell

1 Answer

2

The module was expected to contain an assembly manifest.

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.

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.

answered on Stack Overflow Feb 23, 2017 by natemcmaster

User contributions licensed under CC BY-SA 3.0