dotnet / runtime

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

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

Closed rolfbjarne closed 1 month ago

rolfbjarne commented 2 months ago

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; https://github.com/xamarin/xamarin-macios/pull/20621, so the regression range is: https://github.com/dotnet/runtime/compare/84b3339505...3750ac5161

Known Workarounds

No response

Configuration

No response

Other information

No response

dotnet-policy-service[bot] commented 2 months ago

Tagging subscribers to this area: @mangod9 See info in area-owners.md if you want to be subscribed.

rolfbjarne commented 2 months ago

FWIW this is not a blocker for us for preview 6, I was able to work around it.

mangod9 commented 2 months ago

@steveisok, any recent type system changes you are aware of which might cause this?

steveisok commented 2 months ago

@steveisok, any recent type system changes you are aware of which might cause this?

Not that I'm aware of. We can look into it.

steveisok commented 1 month ago

@davidwrighton could this be related to some of your recent changes?

Alexgoon commented 1 month ago

This issue affects our DevExpress WPF controls. We hope you can resolve it. Thanks!

Junjun-zhao commented 1 month ago

@steveisok @davidwrighton Could you let us know if there are any updates for this issue? We found an another app WolvenKit affected by the same error during the runtime compatibility testing that performed by .NET AppCompat team. During our investigation, the issue is reported by ReactiveUI which a package referred by 3.9k users. Could you help investigate this issue with high priority as it also affects DevExpress controls like Alexgoon mention. It may affect more users in real world.

This is our issue filed about WolvenKit , https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2106458, please check and let us know if anything needed.

steveisok commented 1 month ago

@steveisok @davidwrighton Could you let us know if there are any updates for this issue?

No update yet, unfortunately. I do agree this seems to be a pretty high priority. I will update when I have more info.

Junjun-zhao commented 1 month ago

@steveisok Thanks for your quicky response. In the meantime, could you please help confirm if this is a blocker for .NET 9 Preview 7? Thanks.

cc @PriyaPurkayastha @richamsft

steveisok commented 1 month ago

@steveisok Thanks for your quicky response. In the meantime, could you please help confirm if this is a blocker for .NET 9 Preview 7? Thanks.

I don't feel like this should be a blocker. I am going to try to get it into P7 if there still is time.

Junjun-zhao commented 4 weeks ago

@steveisok We verified this issue for our affected apps, this issue has been fixed on dotnet-sdk-9.0.100-preview.7.24379.15. Thanks.