Skip to content

[net7][Wasm] Type.TypeInitializer.Invoke() does not run the type initializer #69516

Closed

Description

@jeromelaban

Description

Running Type.TypeInitializer.Invoke() does not run the type initializer under net7, where it was under net6.

Reproduction Steps

Considering this code:

Console.WriteLine($"Before Test TypeInitializer");
typeof(Test).TypeInitializer.Invoke(null, null);
Console.WriteLine($"After Test TypeInitializer");

public static class Test
{
    static Test()
    {
        Console.WriteLine("Test: Type Initializer");
    }
}

Expected behavior

net6 shows this:

Before Test TypeInitializer
Test: Type Initializer
After Test TypeInitializer

Actual behavior

net7 shows this:

Before Test TypeInitializer
After Test TypeInitializer

Regression?

Yes

Known Workarounds

Use System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor instead.

Configuration

net7 build: 58fa90b

Other information

I have not tested on the desktop runtime yet.

Activity

  1. ghost added
    untriagedNew issue has not been triaged by the area owner
    on May 18, 2022
  2. added this to the 7.0.0 milestone on Aug 2, 2022
  3. ghost removed
    untriagedNew issue has not been triaged by the area owner
    on Aug 2, 2022
  4. dakersnar commented on Aug 8, 2022

    @dakersnar
    Contributor

    @jkotas We think this might be VM related, can you take a look?

  5. jkotas commented on Aug 8, 2022

    @jkotas
    Member
  6. removed
    untriagedNew issue has not been triaged by the area owner
    on Aug 9, 2022
  7. steveharter commented on Aug 10, 2022

    @steveharter
    Contributor
  8. removed
    untriagedNew issue has not been triaged by the area owner
    on Aug 10, 2022
  9. SamMonoRT commented on Aug 12, 2022

    @SamMonoRT
    Member

    cc @BrzVlad @lambdageek -- marking this a blocking-release, considering its a regression. Assigning to @BrzVlad for tracking.

  10. jkotas commented on Aug 12, 2022

    @jkotas
    Member

    It is this TODO:

    private static void InvokeClassConstructor()
    {
    // [TODO] Mechanism for invoking class constructor
    // See https://github.com/dotnet/runtime/issues/40351
    }

    Related to #40351

  11. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Aug 15, 2022
  12. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Aug 17, 2022
  13. ghost locked as resolved and limited conversation to collaborators on Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions