KEMBAR78
System.InvalidOperationException: Could not execute the method because either the method itself or the containing type is not fully instantiated. · Issue #103891 · dotnet/runtime · GitHub
Skip to content

System.InvalidOperationException: Could not execute the method because either the method itself or the containing type is not fully instantiated. #103891

@rolfbjarne

Description

@rolfbjarne

Description

Calling RuntimeHelpers.RunClassConstructor on a generic type throws an exception.

Reproduction Steps

Test case:

using System.Runtime.CompilerServices;

class App
{
    static void Main()
    {
        foreach (var type in typeof (App).Assembly.GetTypes ())
            RuntimeHelpers.RunClassConstructor (type.TypeHandle);
    }

    static App ()
    {
        Console.WriteLine ("App cctor!");
    }
}

class C<T> {
    static C () {
        Console.WriteLine ("cctor!");
    }
}

Expected behavior

$ dotnet run
App cctor!

Actual behavior

dotnet run
App cctor!
Unhandled exception. System.InvalidOperationException: Could not execute the method because either the method itself or the containing type is not fully instantiated.
   at C`1..cctor()
   at System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(RuntimeTypeHandle type)
   at App.Main() in /Users/rolf/test/dotnet/console/Program.cs:line 8

Regression?

Yes, this works in .NET 8 and 9.0.0-preview.5.24256.1, but fails with 9.0.100-preview.6.24320.12

It started happening in this maestro bump; dotnet/macios#20621, so the regression range is: 84b3339...3750ac5

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions