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
    untriaged
    on May 18, 2022
  2. added this to the 7.0.0 milestone on Aug 2, 2022
  3. ghost removed
    untriaged
    on Aug 2, 2022
  4. added
    untriaged
    and removed on Aug 8, 2022
  5. dakersnar commented on Aug 8, 2022

    @dakersnar
    Contributor

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

  6. jkotas commented on Aug 8, 2022

    @jkotas
    Member
  7. removed
    untriaged
    on Aug 9, 2022
  8. added
    area-VM-reflection-mono
    and removed on Aug 10, 2022
  9. steveharter commented on Aug 10, 2022

    @steveharter
    Contributor
  10. added
    untriaged
    on Aug 10, 2022
  11. removed
    untriaged
    on Aug 10, 2022
  12. 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.

  13. 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

  14. ghost added
    in-pr
    on Aug 15, 2022
  15. ghost removed
    in-pr
    on Aug 17, 2022
  16. 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