Skip to content

Minimal host does not work with NativeAOT #34838

@davidfowl

Description

@davidfowl

Describe the bug

While this isn't yet a fully supported scenario it was possible to build simple ASP.NET Core applications before with NativeAOT. This should in theory still be possible since the WebApplicationBuilder is a thin layer over the existing APIs. That's broken now because we're using Assembly.GetCallingAssembly to get the default application name.

To Reproduce

csproj:

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

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
  </PropertyGroup>

<ItemGroup>
    <PackageReference Include="Microsoft.DotNet.ILCompiler" Version="6.0.0-*" />
</ItemGroup>

</Project>

Program.cs

var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();

app.MapGet("/", context => context.Response.WriteAsync("Hello World!"));

app.Run();
  1. Run dotnet publish -r win-x64 (I was on windows)
  2. Run the resulting published exe.

Exceptions (if any)

WebApplication1\bin\Debug\net6.0\win-x64\publish\WebApplication1.exe
Unhandled Exception: System.PlatformNotSupportedException: Operation is not supported on this platform.
   at System.Reflection.Assembly.GetCallingAssembly() + 0x7a
   at Microsoft.AspNetCore.Builder.WebApplication.CreateBuilder(String[]) + 0x1d
   at <Program>$.<Main>$(String[]) + 0x3e
   at WebApplication1!<BaseAddress>+0x1080f37
   at WebApplication1!<BaseAddress>+0x1080fc5

cc @MichalStrehovsky @jkotas @agocke

Metadata

Metadata

Assignees

Labels

Priority:2Work that is important, but not critical for the releasearea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcbugThis issue describes a behavior which is not expected - a bug.feature-minimal-hosting

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions