How to reproduce:
- Open the attached "IN-151183" project
- Locate Edit > Project Settings > Player > Other Settings > Configuration
- Set Scripting Backend to "IL2CPP"
- Open File > Build Profiles
- Turn on "Create Visual Studio Solution"
- Build a "Windows" player
- Open the generated <YourBuildFolder>\Il2CppOutputProject\Source\il2cppOutput\Assembly-CSharp.cpp
- Using ctrl+f search for “A_Release” and “B_Release”
- Notice the difference between 2 methods
Actual result: B_Release stores the List into the static field and returns with no Il2CppCodeGenWriteBarrier, while A_Release runs the same store and does emit the barrier
Expected result: B_Release emits Il2CppCodeGenWriteBarrier for the store, the same as A_Release
Reproducible with: 6000.0.0f1, 6000.0.84f1, 6000.3.25f1, 6000.6.4f1, 6000.7.0b3, 7000.0.0a5
Reproducible on: Windows 11 (25H2)
Not reproducible on: No other environments tested
Workaround: Move the static field off the ref struct onto a normal class or struct. IL2CPP then emits the barrier for the store (as example struct C in the project writes to a static on a normal class and gets the barrier)