Skip to content

Commit 8d8fa8d

Browse files
fix(audience-sdk): guard IsExternalInit shim against Unity 6 corlib (SDK-256)
Unity 2021.3 needs an internal IsExternalInit shim so the C# compiler can build records with init-only properties. Unity 2022.2+ ships a compiler and corlib that include the real type, raising CS0436 when our shim collides — and on Unity 6's IL2CPP, the linker may bind the wrong definition at the 'with' expression sites in SetConsent/Reset, throwing MissingMethodException at runtime. Wrap the shim in #if !UNITY_2022_2_OR_NEWER so only the toolchains that need it declare the type.
1 parent 11aad56 commit 8d8fa8d

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/Packages/Audience/Runtime/Core/ConsentState.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
#nullable enable
22

3+
// Unity's bundled compiler in 2022.2+ already includes
4+
// System.Runtime.CompilerServices.IsExternalInit. Defining our own would
5+
// raise CS0436 (type conflicts with imported type) and IL2CPP under
6+
// Unity 6 may link the wrong definition — manifesting as
7+
// MissingMethodException at the `with` expression sites in SetConsent
8+
// and Reset. Only declare the shim on the older toolchains that need it.
9+
#if !UNITY_2022_2_OR_NEWER
310
namespace System.Runtime.CompilerServices
411
{
512
// Unity's .NET runtime doesn't include this type, but the C# compiler
613
// needs it to exist to build the ConsentState record below. Declaring
714
// an empty one here gives the compiler what it looks for.
815
internal static class IsExternalInit { }
916
}
17+
#endif
1018

1119
namespace Immutable.Audience
1220
{

0 commit comments

Comments
 (0)