dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.03k stars 4.68k forks source link

ILCompiler failed to ASP.NET WebApplication for ARM64 AOT, with 'System.Net.Quic' #77966

Closed timiil closed 1 year ago

timiil commented 1 year ago

we use the newest version Microsoft.DotNet.ILCompiler 7.0.0-rc.2.22472.3 , just very simple csproject and code here:

src.csproj:

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

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

    <ItemGroup>
        <PackageReference Include="Microsoft.DotNet.ILCompiler" Version="7.0.0-rc.2.22472.3" />
        <PackageReference Include="runtime.linux-arm64.Microsoft.DotNet.ILCompiler" Version="7.0.0-rc.2.22472.3" />
        <PackageReference Include="runtime.linux-x64.Microsoft.DotNet.ILCompiler" Version="7.0.0-rc.2.22472.3" />
    </ItemGroup>

</Project>

Program.cs:

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/test", () => "ok");
app.Run();

i am trying use the newest ARM64 cross builder container here:

docker run -it --rm mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-16.04-cross-arm64-20220824230552-8a8d3be /bin/bash

and then i install dotnet sdk 6 into this contianer , and make the build:

dotnet publish src.csproj -r linux-arm64 -c Release -p:CppCompilerAndLinker=clang-9 -p:SysRoot=/crossrootfs/arm64

and then , it is show the error / warrning string at last:

[very long but seems no faulted]
....
/root/.nuget/packages/microsoft.aspnetcore.app.runtime.linux-arm64/6.0.8/runtimes/linux-arm64/lib/net6.0/Microsoft.Extensions.Hosting.dll : warning IL3053: Assembly 'Microsoft.Extensions.Hosting' produced AOT analysis warnings. [/src/src.csproj]
/root/.nuget/packages/runtime.linux-arm64.microsoft.dotnet.ilcompiler/7.0.0-rc.2.22472.3/framework/System.Linq.Expressions.dll : warning IL3053: Assembly 'System.Linq.Expressions' produced AOT analysis warnings. [/src/src.csproj]
/root/.nuget/packages/microsoft.aspnetcore.app.runtime.linux-arm64/6.0.8/runtimes/linux-arm64/lib/net6.0/Microsoft.Extensions.Configuration.Binder.dll : warning IL3053: Assembly 'Microsoft.Extensions.Configuration.Binder' produced AOT analysis warnings. [/src/src.csproj]
/root/.nuget/packages/microsoft.aspnetcore.app.runtime.linux-arm64/6.0.8/runtimes/linux-arm64/lib/net6.0/Microsoft.Extensions.DependencyInjection.dll : warning IL3053: Assembly 'Microsoft.Extensions.DependencyInjection' produced AOT analysis warnings. [/src/src.csproj]
/root/.nuget/packages/runtime.linux-arm64.microsoft.dotnet.ilcompiler/7.0.0-rc.2.22472.3/framework/System.Net.Http.dll : warning IL3053: Assembly 'System.Net.Http' produced AOT analysis warnings. [/src/src.csproj]
  ILC: Method '[Microsoft.AspNetCore.Server.Kestrel.Transport.Quic]Microsoft.AspNetCore.Hosting.WebHostBuilderQuicExtensions.UseQuic(IWebHostBuilder)' will always throw because: Failed to load type 'System.Net.Quic.Implementations.QuicImplementationProvider' from assembly 'System.Net.Quic, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
  Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
  src -> /src/bin/Release/net6.0/linux-arm64/publish/

the compliation had been done, but when we invoke the executable at a ARM64 ubuntu , it is crash failed by the same exception above:

Failed to load type 'System.Net.Quic.Implementations.QuicImplementationProvider' from assembly 'System.Net.Quic, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

so, what is the problem here ? i had try to rollback a very old version of Microsoft.DotNet.ILCompiler, which is '7.0.0-alpha.1.21601.1', that everything show very perfecttly OK , everything is DONE.

so , is it the newest version ILCompiler problem ? or ASP.NET problem ? or , just give us some hint how to deal with this ?

dotnet-issue-labeler[bot] commented 1 year ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

MichalStrehovsky commented 1 year ago

Failed to load type 'System.Net.Quic.Implementations.QuicImplementationProvider' from assembly 'System.Net.Quic, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

There was a breaking change in Quic and the version that ASP.NET 6.0 is compiled with is not compatible with the 7.0 ILCompiler package (that contains the new Quic implementation).

You need to target .NET 7 to use Native AOT.