Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidCastException when running BenchmarkDotNet with .NET 9 (RC1) AoT #2651

Closed
eNeRGy164 opened this issue Sep 26, 2024 · 2 comments
Closed

Comments

@eNeRGy164
Copy link

When running benchmarks against .NET 9 RC1 AoT, I encountered an InvalidCastException on the generated project.
This issue seems to be related to/triggered by the <IlcGenerateCompleteTypeMetadata> property in the auto-generated .csproj file.

Steps to Reproduce

  1. Clone https://github.com/eNeRGy164/AdventOfPerformance/tree/net90

  2. Run BenchmarkDotNet with .NET 9 AoT using the command:

    dotnet run -c Release -f net9.0 -- --runtimes nativeaot90 --filter *PuzzlePart1Benchmarks*
  3. Observe the exception being thrown during the build process.

    [G:\eNeRGy164\AdventOfPerformance\AdventOfPerformance\bin\Release\net9.0\dc62efe0-07da-4394-9f10-feb11cf922fe\BenchmarkDotNet.Autogenerated.csproj]
      Generating native code
    EXEC : error : Specified cast is not valid. [G:\eNeRGy164\AdventOfPerformance\AdventOfPerformance\bin\Release\net9.0\dc62efe0-07da-4394-9f10-feb11cf922fe\BenchmarkDotNet.Autogenerated.csproj]
      System.InvalidCastException: Specified cast is not valid.
         at ILCompiler.CompilerTypeSystemContext.EnsureLoadableTypeUncached(TypeDesc) + 0x3eb
         at ILCompiler.CompilerTypeSystemContext.EnsureLoadableType(TypeDesc) + 0x5a
         at ILCompiler.LibraryRootProvider.CheckCanGenerateMethod(MethodDesc) + 0x4c
         at ILCompiler.DependencyAnalysis.TypeMetadataNode.GetStaticDependencies(NodeFactory) + 0x48a
         at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.GetStaticDependenciesImpl(DependencyNodeCore`1) + 0x56
         at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.GetStaticDependencies(DependencyNodeCore`1) + 0xce
         at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ProcessMarkStack() + 0xed
         at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ComputeMarkedNodes() + 0x49
         at ILCompiler.ILScanner.ILCompiler.IILScanner.Scan() + 0x1b
         at ILCompiler.Program.<Run>g__RunScanner|4_0(Program.<>c__DisplayClass4_0&) + 0x1fa
         at ILCompiler.Program.Run() + 0x28ff
         at ILCompiler.ILCompilerRootCommand.<>c__DisplayClass240_0.<.ctor>b__0(ParseResult) + 0x321
    C:\Users\micha\.nuget\packages\microsoft.dotnet.ilcompiler\9.0.0-rc.1.24431.7\build\Microsoft.NETCore.Native.targets(317,5): error MSB3073: The command ""C:\Users\micha\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\9.0.0-rc.1.24431.7\tools\\ilc" @"G:\eNeRGy164\AdventOfPerformance\AdventOfPerformance\bin\Release\net9.0\dc62efe0-07da-4394-9f10-feb11cf922fe\obj\Release\net9.0/native\dc62efe0-07da-4394-9f10-feb11cf922fe.ilc.rsp"" exited with code 1. [G:\eNeRGy164\AdventOfPerformance\AdventOfPerformance\bin\Release\net9.0\dc62efe0-07da-4394-9f10-feb11cf922fe\BenchmarkDotNet.Autogenerated.csproj]

Workaround

Removing the <IlcGenerateCompleteTypeMetadata> property from the generated .csproj file resolves the issue, and the .bat file runs without exceptions.

Additional Details

BenchmarkDotNet version: 0.14.0
.NET SDK version: 9.0.100-rc.1.24452.12
This issue does not occur with SDK 8.0 and nativeaot80 or SDK 9.0 RC1 and net90
Link to the branch: net90

I'm not sure if this is a specific BenchmarkDotNet issue,or related to the ILCompiler itself.

@adamsitnik
Copy link
Member

Hello @eNeRGy164

Big thanks for a detailed bug report!

Could you please check if this fix: #2616 has solved the problem?

To do that you need to download a preview verion from our CI feed: https://benchmarkdotnet.org/articles/guides/nuget.html?q=nightly#nightly

@eNeRGy164
Copy link
Author

eNeRGy164 commented Sep 26, 2024

The latest nightly does indeed fix this. I did only search inside this repo, so didn't find the related issue. 🥳

Fixed by #2616

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants