Sdk: Kestrel BadImageFormatException

Created on 5 Feb 2018  路  5Comments  路  Source: dotnet/sdk

Steps to reproduce

Create a new webAPI from the command line
dotnet new webapi

Run from the console
dot new run

Visit the http or https URL
for example:
http://localhost:16767/api/values

Expected behavior

Expect to see the Json formatted response of the basic GET, value1 and value 2

Actual behavior

Following is desplayed in console:
fail: Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv[0]
UvAllocCb
System.BadImageFormatException: Bad IL format.
at System.Buffers.OwnedMemory1.Pin(Int32 byteOffset) at System.Memory1.Retain(Boolean pin)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvConnection.OnAlloc(UvStreamHandle handle, Int32 suggestedSize)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvConnection.<>c.<.cctor>b__24_1(UvStreamHandle handle, Int32 suggestedsize, Object state)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle.UvAllocCb(IntPtr handle, Int32 suggested_size, uv_buf_t& buf)

Unhandled Exception: System.BadImageFormatException: Bad IL format.
at System.Buffers.OwnedMemory1.Pin(Int32 byteOffset) at System.Memory1.Retain(Boolean pin)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvConnection.OnAlloc(UvStreamHandle handle, Int32 suggestedSize)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvConnection.<>c.<.cctor>b__24_1(UvStreamHandle handle, Int32 suggestedsize, Object state)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle.UvAllocCb(IntPtr handle, Int32 suggested_size, uv_buf_t& buf)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.UvStreamHandle.<>c.<.cctor>b__20_1(IntPtr handle, Int32 suggested_size, uv_buf_t& buf)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions.NativeMethods.uv_run(UvLoopHandle handle, Int32 mode)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking.LibuvFunctions.run(UvLoopHandle handle, Int32 mode)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvThread.ThreadStart(Object parameter)
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.LibuvThread.StopAsync(TimeSpan timeout)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.LibuvTransport.StopAsync()
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.StopAsync(CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.StopAsync(CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.Dispose()
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.Dispose()
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.Dispose()
at Microsoft.Extensions.DependencyInjection.ServiceProvider.Dispose()
at Microsoft.AspNetCore.Hosting.Internal.WebHost.Dispose()
at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token, String shutdownMessage)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host)
at myApi.Program.Main(String[] args) in d:\dev\myApi\Program.cs:line 17

Environment data

dotnet --info output:
.NET Command Line Tools (2.1.300-preview2-008044)

Product Information:
Version: 2.1.300-preview2-008044
Commit SHA-1 hash: c22f7e29a0

Runtime Environment:
OS Name: Windows
OS Version: 10.0.16299
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnetsdk\2.1.300-preview2-008044\

Microsoft .NET Core Shared Framework Host

Version : 2.1.0-preview2-26130-06
Build : b13a0d5c331f374afd35ded57b9a4b4ab128864c

Most helpful comment

The issue has been fixed in kestrel https://github.com/aspnet/KestrelHttpServer/issues/2271 but it hasn't propagated through all the build layers as yet.

All 5 comments

Same problem, was about to post this too. Is the installed path OK? C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.all\2.1.0-preview1-28124\build\netcoreapp2.1\Microsoft.AspNetCore.All.targets

And this is the .csproj, not sure if it helps:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <RuntimeFrameworkVersion>2.1.0-preview1-26115-03</RuntimeFrameworkVersion>
    <NETStandardImplicitPackageVersion>2.0.1</NETStandardImplicitPackageVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.0-preview1-28124" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.1.0-preview1-28124" />
  </ItemGroup>

</Project>

Edit: I created a MVC app. With dotnet new mvc

The issue has been fixed in kestrel https://github.com/aspnet/KestrelHttpServer/issues/2271 but it hasn't propagated through all the build layers as yet.

Awesome, can confirm that it works. Downgraded to 2.1.0-preview1-28226. Found in: https://github.com/dotnet/versions/tree/master/build-info/dotnet/product/cli/release/2.1#product-build-cli-build-20180202-02-1347550

@livarcocc closing this as this is an ASP.NET issue. :)

thanks @muratg

Was this page helpful?
0 / 5 - 0 ratings