dotnet / runtime

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

ilc compilation failure: Invalid IL or CLR metadata #99047

Closed hez2010 closed 8 months ago

hez2010 commented 8 months ago

Description

I'm experimenting with my profile guided aot runtime directives assistant against an asp.net core + efcore app, and managed to produce a rd.xml for it. But when I build it with NativeAOT, it failed with Invalid IL or CLR metadata on [Microsoft.AspNetCore.Identity.EntityFrameworkCore]Microsoft.Extensions.DependencyInjection.IdentityEntityFrameworkBuilderExtensions.AddStores(IServiceCollection,Type,Type,Type)

Reproduction Steps

Repro: WebSample.zip

Expected behavior

No compilation failure.

Actual behavior

ILC: Compiling [Microsoft.AspNetCore.Identity.EntityFrameworkCore]Microsoft.Extensions.DependencyInjection.IdentityEntityFrameworkBuilderExtensions.AddStores(IServiceCollection,Type,Type,Type)...
EXEC : error : Invalid IL or CLR metadata [D:\source\repos\Test\WebSample\WebSample.csproj]
  Internal.TypeSystem.TypeSystemException+InvalidProgramException: Invalid IL or CLR metadata
     at Internal.TypeSystem.ThrowHelper.ThrowInvalidProgramException() + 0x24
     at Internal.JitInterface.CorInfoImpl.CompileMethodInternal(IMethodNode, MethodIL) + 0x22a
     at Internal.JitInterface.CorInfoImpl.CompileMethod(MethodCodeNode, MethodIL) + 0x5c
     at ILCompiler.RyuJitCompilation.CompileSingleMethod(CorInfoImpl, MethodCodeNode) + 0xc7
     at ILCompiler.RyuJitCompilation.CompileSingleThreaded(List`1) + 0x24e
     at ILCompiler.RyuJitCompilation.ComputeDependencyNodeDependencies(List`1 obj) + 0x149
     at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ComputeMarkedNodes() + 0x95
     at ILCompiler.RyuJitCompilation.CompileInternal(String, ObjectDumper) + 0x1f
     at ILCompiler.Compilation.ILCompiler.ICompilation.Compile(String, ObjectDumper) + 0x2d
     at ILCompiler.Program.Run() + 0x2772
     at ILCompiler.ILCompilerRootCommand.<>c__DisplayClass227_0.<.ctor>b__0(ParseResult result) + 0x315

Regression?

No response

Known Workarounds

No response

Configuration

.NET 8.0.200

Other information

No response

ghost commented 8 months ago

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas See info in area-owners.md if you want to be subscribed.

Issue Details
### Description I'm experimenting with my profile guided aot runtime directives assistant against an asp.net core + efcore app, and managed to produce a rd.xml for it. But when I build it with NativeAOT, it failed with `Invalid IL or CLR metadata` on `[Microsoft.AspNetCore.Identity.EntityFrameworkCore]Microsoft.Extensions.DependencyInjection.IdentityEntityFrameworkBuilderExtensions.AddStores(IServiceCollection,Type,Type,Type)` ### Reproduction Steps Repro: [WebSample.zip](https://github.com/dotnet/runtime/files/14435308/WebSample.zip) ### Expected behavior No compilation failure. ### Actual behavior ``` ILC: Compiling [Microsoft.AspNetCore.Identity.EntityFrameworkCore]Microsoft.Extensions.DependencyInjection.IdentityEntityFrameworkBuilderExtensions.AddStores(IServiceCollection,Type,Type,Type)... EXEC : error : Invalid IL or CLR metadata [D:\source\repos\Test\WebSample\WebSample.csproj] Internal.TypeSystem.TypeSystemException+InvalidProgramException: Invalid IL or CLR metadata at Internal.TypeSystem.ThrowHelper.ThrowInvalidProgramException() + 0x24 at Internal.JitInterface.CorInfoImpl.CompileMethodInternal(IMethodNode, MethodIL) + 0x22a at Internal.JitInterface.CorInfoImpl.CompileMethod(MethodCodeNode, MethodIL) + 0x5c at ILCompiler.RyuJitCompilation.CompileSingleMethod(CorInfoImpl, MethodCodeNode) + 0xc7 at ILCompiler.RyuJitCompilation.CompileSingleThreaded(List`1) + 0x24e at ILCompiler.RyuJitCompilation.ComputeDependencyNodeDependencies(List`1 obj) + 0x149 at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ComputeMarkedNodes() + 0x95 at ILCompiler.RyuJitCompilation.CompileInternal(String, ObjectDumper) + 0x1f at ILCompiler.Compilation.ILCompiler.ICompilation.Compile(String, ObjectDumper) + 0x2d at ILCompiler.Program.Run() + 0x2772 at ILCompiler.ILCompilerRootCommand.<>c__DisplayClass227_0.<.ctor>b__0(ParseResult result) + 0x315 ``` ### Regression? _No response_ ### Known Workarounds _No response_ ### Configuration .NET 8.0.200 ### Other information _No response_
Author: hez2010
Assignees: -
Labels: `untriaged`, `area-NativeAOT-coreclr`
Milestone: -
jkotas commented 8 months ago

rdxml is unsupported: https://github.com/dotnet/runtime/blob/main/src/coreclr/nativeaot/docs/rd-xml-format.md . We plan to delete the support eventually.

This error means that your rdxml is malformed. We know that the experience for diagnosing wrong rdxml is bad. We do not plan to improve it.

profile guided aot runtime directives assistant

You may want to consider providing this information to the AOT compiler via additional C# source or IL assembly that has dynamically unreachable method with additional roots.

hez2010 commented 8 months ago

This error means that your rdxml is malformed.

It seems that the types in rdxml were rooted correctly, but failed at codegen for Microsoft.Extensions.DependencyInjection.IdentityEntityFrameworkBuilderExtensions.AddStores(IServiceCollection,Type,Type,Type): https://github.com/dotnet/aspnetcore/blob/3e168fe85e2330621ed12d9c9524c80e0f743dc6/src/Identity/EntityFrameworkCore/src/IdentityEntityFrameworkBuilderExtensions.cs#L29

jkotas commented 8 months ago

rdxml is not required to reproduce this. It is enough to just call the AddStores method in the specific EF core version.

jkotas commented 8 months ago

Thank you for reporting this!