Unable to build IL2CPP in Unity 2021.3.8f1

Hi there,

I’m trying to build in IL2CPP but I keep getting errors. In Mono it seems to work fine but I can’t fix this IL2CPP error no matter what I try.

What I have:

  • Unity Hub: IL2CPP module installed
  • VS: Practically everything installed except “Other toolsets”,. I also added Windows 11 SDK and the v142 modules.

The errors I get:

Error 1

Building Library\Bee\artifacts\WinPlayerBuildProgram\ei6vj\ccap_u_vm6.lump.obj failed with output:
5ihu_vm6.lump.cpp
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(71): error C2039: 'hash_compare': is not a member of 'stdext'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\include\iterator(1447): note: see declaration of 'stdext'
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(71): error C2065: 'hash_compare': undeclared identifier
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(71): error C2275: 'Key': expected an expression instead of a type
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(38): error C2976: 'Il2CppReaderWriterLockedHashMap': too few template arguments
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(75): note: see declaration of 'Il2CppReaderWriterLockedHashMap'
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(38): error C2955: 'Il2CppReaderWriterLockedHashMap': use of class template requires template argument list
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(75): note: see declaration of 'Il2CppReaderWriterLockedHashMap'
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(47): error C2955: 'Il2CppReaderWriterLockedHashMap': use of class template requires template argument list
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(75): note: see declaration of 'Il2CppReaderWriterLockedHashMap'
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(385): error C2662: 'bool Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>::TryGet(const Il2CppHashMap<Key,T,HashFcn,EqualKey,Alloc>::key_type &,T *)': cannot convert 'this' pointer from 'PointerTypeMap' to 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc> &'
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(385): note: Reason: cannot convert from 'PointerTypeMap' to 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>'
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(385): note: Conversion requires a second user-defined-conversion operator or constructor
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(90): note: see declaration of 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>::TryGet'
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(385): note: while trying to match the argument list '(Il2CppClass *, Il2CppClass **)'
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(438): error C2662: 'bool Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>::Add(const Il2CppHashMap<Key,T,HashFcn,EqualKey,Alloc>::key_type &,const T &)': cannot convert 'this' pointer from 'PointerTypeMap' to 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc> &'
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(438): note: Reason: cannot convert from 'PointerTypeMap' to 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>'
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(438): note: Conversion requires a second user-defined-conversion operator or constructor
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(102): note: see declaration of 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>::Add'
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(438): note: while trying to match the argument list '(Il2CppClass *, Il2CppClass *)'
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(1135): error C2955: 'Il2CppReaderWriterLockedHashMap': use of class template requires template argument list
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(75): note: see declaration of 'Il2CppReaderWriterLockedHashMap'
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(1135): error C2662: 'Il2CppHashMap<Key,T,HashFcn,EqualKey,Alloc>::iterator Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>::UnlockedBegin(void)': cannot convert 'this' pointer from 'PointerTypeMap' to 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc> &'
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(1135): note: Reason: cannot convert from 'PointerTypeMap' to 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>'
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(1135): note: Conversion requires a second user-defined-conversion operator or constructor
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(121): note: see declaration of 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>::UnlockedBegin'
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(1135): note: while trying to match the argument list '()'
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(1135): error C2662: 'Il2CppHashMap<Key,T,HashFcn,EqualKey,Alloc>::iterator Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>::UnlockedEnd(void)': cannot convert 'this' pointer from 'PointerTypeMap' to 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc> &'
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(1135): note: Reason: cannot convert from 'PointerTypeMap' to 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>'
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(1135): note: Conversion requires a second user-defined-conversion operator or constructor
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(127): note: see declaration of 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>::UnlockedEnd'
C:\Program Files\Unity\Hub\Editor\2021.3.8f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(1135): note: while trying to match the argument list '()'
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

Error 2 (seems easy enough this one - though setting is removed in this version of Unity

BuildFailedException: Incremental Player build failed!
UnityEditor.Modules.BeeBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args) (at <5f40cdb07bd44d76a23dad985a4ec283>:0)
UnityEditor.Modules.DefaultBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <5f40cdb07bd44d76a23dad985a4ec283>:0)
UnityEditor.WindowsStandalone.WinPlayerPostProcessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at C:/buildslave/unity/build/PlatformDependent/WinPlayer/Extensions/Managed/WinPlayerPostProcessor.cs:38)
UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.Int32 subtarget, System.String installPath, System.String companyName, System.String productName, System.Int32 width, System.Int32 height, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <5f40cdb07bd44d76a23dad985a4ec283>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

Error 3. Caused by other 2 - adding for ref

Build completed with a result of 'Failed' in 63 seconds (62941 ms)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

Error 4. Same story as error 4. Just adding for ref

UnityEditor.BuildPlayerWindow+BuildMethodException: 3 errors
  at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x002da] in <5f40cdb07bd44d76a23dad985a4ec283>:0
  at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x00080] in <5f40cdb07bd44d76a23dad985a4ec283>:0
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

If anyone can help with this, that would be great. I am really lost as to why this is not working at this point now that pretty much everything is installed.

Update:
After this, In desperation I upgraded to a different Unity version. (2021.3.21f1) and magically it worked.

Seems the Unity version is the problem.

Hi indeed, you were running into Workaround for building with IL2CPP with Visual Studio 2022 17.4 .