Skip to content

UnsafeAccessor changes not observed when used in a ReadyToRun Module Initializer in .NET 11 #134283

Description

@TonyValenti

Description

When Assembly2's [ModuleInitializer] uses UnsafeAccessor to set a private variable in Assembly3, the changes are not observed. This only seems to happen when ReadyToRun is enabled.

Reproduction Steps

Run the code below in VS. It will correctly show:
IsSet: True

Then, publish it using the included publishing profile. When you run it, it will INCORRECTLY show:
IsSet: False

StaticTests.zip

Expected behavior

When published with ReadyToRun, it should show:
IsSet: True

Actual behavior

When published with ReadyToRun, it incorrectly shows:
IsSet: False

Regression?

I tested this in .NET 10 and observed the same problem.

Known Workarounds

It seems like refactoring the code so that things aren't called from within the module initializer seem to work.

Configuration

.NET 11 RC1. x64.
ReadyToRun

Other information

No response

Activity

  1. TonyValenti commented on Sep 21, 2026

    @TonyValenti
    Author

    Could someone take a look at this please?

  2. jkotas commented on Sep 21, 2026

    @jkotas
    Member
  3. TonyValenti commented on Oct 1, 2026

    @TonyValenti
    Author

    I wanted to check in on this. Any chance it can be merged soon?

  4. added a commit that references this issue on Oct 7, 2026
    8367641
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

  • Status
    No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions