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

Failed to create generic virtual method implementation #104913

Closed
MackinnonBuck opened this issue Jul 15, 2024 · 1 comment · Fixed by #104965
Closed

Failed to create generic virtual method implementation #104913

MackinnonBuck opened this issue Jul 15, 2024 · 1 comment · Fixed by #104965

Comments

@MackinnonBuck
Copy link
Member

MackinnonBuck commented Jul 15, 2024

Description

NativeAOT fails to generate the implementation for a generic virtual method when:

  • Its type argument is constrained to an interface declaring a generic static abstract interface method
  • The implementation invokes the generic abstract interface method, passing a value type as the type argument

Full code snippet is included in the repro steps.

Reproduction Steps

  1. Create a new console app (dotnet new console)
  2. Edit the project file to include <PublishAot>true</PublishAot>
  3. Replace Program.cs with the following:
    ((IFoo)new Foo()).Invoke<Bar>();
    
    interface IFoo
    {
        void Invoke<T>() where T : IBar;
    }
    
    class Foo : IFoo
    {
        public void Invoke<T>() where T : IBar
            => T.Invoke<int>(); // Fails for any value type, succeeds for any reference type
    }
    
    interface IBar
    {
        static abstract void Invoke<T>();
    }
    
    class Bar : IBar
    {
        public static void Invoke<T>()
            => Console.WriteLine("Hello, world!");
    }
  4. Run dotnet publish in the folder containing the project
  5. Navigate to the publish output and run the produced executable

Expected behavior

The program outputs "Hello, world!"

Actual behavior

The program crashes with the following output:

Process terminated. Failed to create generic virtual method implementation

Declaring type: Foo
Method name: Invoke
Instantiation:
  Argument 00000000: Bar

   at System.RuntimeExceptionHelpers.FailFast(String, Exception, String, RhFailFastReason, IntPtr, IntPtr) + 0x229
   at Internal.Runtime.TypeLoader.TypeLoaderEnvironment.ResolveGenericVirtualMethodTarget(RuntimeTypeHandle, RuntimeMethodHandle) + 0x2a7
   at System.Runtime.TypeLoaderExports.<>c.<GVMLookupForSlotSlow>b__8_0(IntPtr, IntPtr, Object, IntPtr&) + 0x3e
   at System.Runtime.TypeLoaderExports.CacheMiss(IntPtr, IntPtr, RuntimeObjectFactory, Object) + 0x3c
   at System.Runtime.TypeLoaderExports.GVMLookupForSlotSlow(Object, RuntimeMethodHandle) + 0x68
   at System.Runtime.TypeLoaderExports.GVMLookupForSlot(Object, RuntimeMethodHandle) + 0xa2
   at Program.<Main>$(String[] args) + 0x23

Regression?

Tested against the following versions of Microsoft.NETCore.App:

  • 9.0.0-preview.6.24327.7
  • 8.0.7
  • 7.0.20

The problem reproduces on all of these versions, so I'm inclined to think this is not a regression.

Known Workarounds

No response

Configuration

.NET SDK version: 9.0.100-preview.6.24328.19
OS: Windows 11 Enterprise Build 22631.3880
Architecture: x64

I haven't tested the repro on other configurations.

Other information

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jul 15, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Jul 15, 2024
@vcsjones vcsjones added area-NativeAOT-coreclr and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jul 15, 2024
Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants