2
votes

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?

1
could you share that Program.cs with us?Callum Linington
have you stepped through the code and looked at the exception message and inner exceptions?Callum Linington
I never get to any code to step through. The very first thing that happens is the application enters break mode and says "Your app has entered a break state, but no code is currently executing that is supported by the selected debug engine (e.g. only native runtime code is executing)."Zach Becknell
Are you compiling with 64bit?Ofir Winegarten
Can you also share your project.json or csproj file?natemcmaster

1 Answers

2
votes

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.