UPDATE: The fix is included in Unity 2020.3.42f1, 2021.3.14f1, 2022.1.23f1, 2022.2.0b16 and 2023.1.0a19.
Visual Studio 2022 17.4 update has introduced a breaking change in their standard C++ headers which causes parts of IL2CPP runtime fail to compile if you upgrade to this version of Visual Studio:
[111/231 3s] C_Win64_VS2022 Library/Bee/artifacts/WinPlayerBuildProgram/ei6vj/5dkl_c_vm6.lump.obj
##### CommandLine
"C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/Tools/MSVC/14.34.31932/bin/Hostx64/x64/cl.exe" /Oi /D_WIN64 /D_AMD64_ /FC "Library\Bee\artifacts\WinPlayerBuildProgram\ei6vj\ij4c_vm6.lump.cpp" /MT /c /bigobj /utf-8 /cgthreads2 /Ox /Gw /Zo /Oy- /d2ssa-cse- /TP /EHs /GR- /Gy /nologo /GF /Z7 /GS- /W3 /wd4102 /wd4800 /wd4056 /wd4190 /wd4723 /wd4467 /wd4503 /wd4996 /wd4200 /wd4834 /wd4722 /DUNICODE /D_UNICODE /D_SECURE_SCL=0 /D_ITERATOR_DEBUG_LEVEL=0 /D_HAS_ITERATOR_DEBUGGING=0 /DWINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP /DWIN32 /DWINDOWS /D_WINDOWS /DBASELIB_INLINE_NAMESPACE=il2cpp_baselib /DBASELIB_USE_DYNAMICLIBRARY=1 /DIL2CPP_MONO_DEBUGGER_DISABLED /DRUNTIME_IL2CPP /DIL2CPP_ENABLE_WRITE_BARRIERS=1 /DIL2CPP_INCREMENTAL_TIME_SLICE=3 /DGC_NOT_DLL /DWIN32_THREADS /DIL2CPP_DEFAULT_DATA_DIR_PATH=Data /DWINDOWS_SDK_BUILD_VERSION=22621 /DNOMINMAX /DNDEBUG /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_WINSOCK_DEPRECATED_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_SCL_SECURE_NO_WARNINGS /I"." /I"E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\pch" /I"E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp" /I"E:\Builds\2021.3.10f1\Editor\Data\il2cpp\external\baselib\Include" /I"E:\Builds\2021.3.10f1\Editor\Data\il2cpp\external\baselib\Platforms\Windows\Include" /I"E:\Builds\2021.3.10f1\Editor\Data\il2cpp\external\bdwgc\include" /I"C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.34.31932\include" /I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\shared" /I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um" /I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\winrt" /I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt" /I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\cppwinrt" /Fo"Library\Bee\artifacts\WinPlayerBuildProgram\ei6vj\5dkl_c_vm6.lump.obj" /D_HAS_AUTO_PTR_ETC=1 /D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS /D_SILENCE_ALL_CXX20_DEPRECATION_WARNINGS /Zc:__cplusplus /std:c++17
##### Custom Environment Variables
PATH=C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.34.31932\bin\Hostx64\x64;C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64
_MSPDBSRV_ENDPOINT_=7360085491879648213
##### ExitCode
2
##### Output
ij4c_vm6.lump.cpp
E:\Builds\2021.3.10f1\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\Preview\VC\Tools\MSVC\14.34.31932\include\iterator(1426): note: see declaration of 'stdext'
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(71): error C2065: 'hash_compare': undeclared identifier
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(71): error C2275: 'Key': expected an expression instead of a type
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(38): error C2976: 'Il2CppReaderWriterLockedHashMap': too few template arguments
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(75): note: see declaration of 'Il2CppReaderWriterLockedHashMap'
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(38): error C2974: 'Il2CppReaderWriterLockedHashMap': invalid template argument for 'HashFcn', type expected
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(75): note: see declaration of 'Il2CppReaderWriterLockedHashMap'
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(38): error C2955: 'Il2CppReaderWriterLockedHashMap': use of class template requires template argument list
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(75): note: see declaration of 'Il2CppReaderWriterLockedHashMap'
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(47): error C2955: 'Il2CppReaderWriterLockedHashMap': use of class template requires template argument list
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(75): note: see declaration of 'Il2CppReaderWriterLockedHashMap'
E:\Builds\2021.3.10f1\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> &'
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(385): note: Reason: cannot convert from 'PointerTypeMap' to 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>'
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(385): note: Conversion requires a second user-defined-conversion operator or constructor
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(90): note: see declaration of 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>::TryGet'
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(385): note: while trying to match the argument list '(Il2CppClass *, Il2CppClass **)'
E:\Builds\2021.3.10f1\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> &'
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(438): note: Reason: cannot convert from 'PointerTypeMap' to 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>'
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(438): note: Conversion requires a second user-defined-conversion operator or constructor
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(102): note: see declaration of 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>::Add'
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(438): note: while trying to match the argument list '(Il2CppClass *, Il2CppClass *)'
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(1135): error C2955: 'Il2CppReaderWriterLockedHashMap': use of class template requires template argument list
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(75): note: see declaration of 'Il2CppReaderWriterLockedHashMap'
E:\Builds\2021.3.10f1\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> &'
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(1135): note: Reason: cannot convert from 'PointerTypeMap' to 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>'
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(1135): note: Conversion requires a second user-defined-conversion operator or constructor
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(121): note: see declaration of 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>::UnlockedBegin'
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(1135): note: while trying to match the argument list '()'
E:\Builds\2021.3.10f1\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> &'
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(1135): note: Reason: cannot convert from 'PointerTypeMap' to 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>'
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(1135): note: Conversion requires a second user-defined-conversion operator or constructor
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(127): note: see declaration of 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>::UnlockedEnd'
E:\Builds\2021.3.10f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(1135): note: while trying to match the argument list '()'
We reported this to Microsoft but unfortunately this change was by design: Developer Community
We are currently preparing a fix in Unity for this for all supported Unity releases. I will update this thread once the fix has gone out (you can track it here: Unity Issue Tracker - [IL2CPP] Windows builds fails when using VS 2022 17.4.0 Preview). In the mean time, you can workaround this issue by adding this script to anywhere within your project:
#if UNITY_EDITOR
using System;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
public class MsvcStdextWorkaround : IPreprocessBuildWithReport
{
const string kWorkaroundFlag = "/D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS";
public int callbackOrder => 0;
public void OnPreprocessBuild(BuildReport report)
{
var clEnv = Environment.GetEnvironmentVariable("_CL_");
if (string.IsNullOrEmpty(clEnv))
{
Environment.SetEnvironmentVariable("_CL_", kWorkaroundFlag);
}
else if (!clEnv.Contains(kWorkaroundFlag))
{
clEnv += " " + kWorkaroundFlag;
Environment.SetEnvironmentVariable("_CL_", clEnv);
}
}
}
#endif // UNITY_EDITOR
UPDATE: The fix is included in Unity 2020.3.42f1, 2021.3.14f1, 2022.1.23f1, 2022.2.0b16 and 2023.1.0a19.
8553044–1143662–MsvcStdextWorkaround.cs (773 Bytes)