Search Issue Tracker
Fixed in 2021.3.18f1, 2022.2.5f1, 2023.1.0a26
Marshal.OffsetOf returns invalid value in IL2CPP for misaligned fields on macOS
Marshal.OffsetOf returns invalid value in IL2CPP for misaligned fields on macOS, .NET 7.0/ Unity Mono return correct value.
On 2022.2.0b14 on macOS (Arm) it prints:
"foo 1" under Mono (Editor and Standalone), and .NET 7.0
"foo 0" under IL2CPP
This was working previously at least in 2020.3, likely also in 2021.x
Reprocase is as following:
[StructLayout(LayoutKind.Explicit, Size = 3)]
public ushort foo;
public void ReproCase()
foreach (var field in typeof(Repro).GetFields())
var offset = (uint) Marshal.OffsetOf(field.DeclaringType, field.Name).ToInt32();
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
- Visual Studio debugger doesn't show full properties of animation variables on Android and IOS Platforms when using IL2CPP Scripting Backend
- [Linux][Plastic SCM] "Access Denied" error when downloading Plastic SCM Cloud Edition through the Editor
- UpdateRendererBonudingVolumes process takes more time when disabled Renderers are used
- "ArgumentNullException: Value cannot be null" error is thrown when selecting a Visual Element with a custom Render Texture set as a background
- Changes are not saved when changing Styles' orders in the UI Builder
Resolution Note (fix version 2023.1.0a26):
Fixed Marshal.OffsetOf returning invalid values in IL2CPP for misaligned fields on macOS.