Search Unity

Bug IL2CPP error on Building for Windows

Discussion in 'Editor & General Support' started by wagenheimer, Oct 21, 2022.

  1. wagenheimer

    wagenheimer

    Joined:
    Jun 1, 2018
    Posts:
    323
    Unity 2021.3.11. I cannot build for Windows.... Linux/Mac/Nintendo Switch is working as expected. What I can try to fix it?

    Code (CSharp):
    1. Building Library\Bee\artifacts\WinPlayerBuildProgram\t2s8s\cc18_0_vm6.lump.obj failed with output:
    2. xbo0_vm6.lump.cpp
    3. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(71): error C2039: 'hash_compare': is not a member of 'stdext'
    4. C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.34.31931\include\iterator(1426): note: see declaration of 'stdext'
    5. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(71): error C2065: 'hash_compare': undeclared identifier
    6. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(71): error C2275: 'Key': expected an expression instead of a type
    7. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(38): error C2976: 'Il2CppReaderWriterLockedHashMap': too few template arguments
    8. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(75): note: see declaration of 'Il2CppReaderWriterLockedHashMap'
    9. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(38): error C2974: 'Il2CppReaderWriterLockedHashMap': invalid template argument for 'HashFcn', type expected
    10. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(75): note: see declaration of 'Il2CppReaderWriterLockedHashMap'
    11. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(38): error C2955: 'Il2CppReaderWriterLockedHashMap': use of class template requires template argument list
    12. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(75): note: see declaration of 'Il2CppReaderWriterLockedHashMap'
    13. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(47): error C2955: 'Il2CppReaderWriterLockedHashMap': use of class template requires template argument list
    14. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(75): note: see declaration of 'Il2CppReaderWriterLockedHashMap'
    15. C:\Unity\2021.3.11f1\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> &'
    16. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(385): note: Reason: cannot convert from 'PointerTypeMap' to 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>'
    17. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(385): note: Conversion requires a second user-defined-conversion operator or constructor
    18. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(90): note: see declaration of 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>::TryGet'
    19. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(385): note: while trying to match the argument list '(Il2CppClass *, Il2CppClass **)'
    20. C:\Unity\2021.3.11f1\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> &'
    21. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(438): note: Reason: cannot convert from 'PointerTypeMap' to 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>'
    22. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(438): note: Conversion requires a second user-defined-conversion operator or constructor
    23. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(102): note: see declaration of 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>::Add'
    24. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(438): note: while trying to match the argument list '(Il2CppClass *, Il2CppClass *)'
    25. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(1135): error C2955: 'Il2CppReaderWriterLockedHashMap': use of class template requires template argument list
    26. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(75): note: see declaration of 'Il2CppReaderWriterLockedHashMap'
    27. C:\Unity\2021.3.11f1\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> &'
    28. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(1135): note: Reason: cannot convert from 'PointerTypeMap' to 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>'
    29. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(1135): note: Conversion requires a second user-defined-conversion operator or constructor
    30. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(121): note: see declaration of 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>::UnlockedBegin'
    31. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(1135): note: while trying to match the argument list '()'
    32. C:\Unity\2021.3.11f1\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> &'
    33. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(1135): note: Reason: cannot convert from 'PointerTypeMap' to 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>'
    34. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(1135): note: Conversion requires a second user-defined-conversion operator or constructor
    35. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\utils\Il2CppHashMap.h(127): note: see declaration of 'Il2CppReaderWriterLockedHashMap<Key,T,HashFcn,EqualKey,Alloc>::UnlockedEnd'
    36. C:\Unity\2021.3.11f1\Editor\Data\il2cpp\libil2cpp\vm\MetadataCache.cpp(1135): note: while trying to match the argument list '()'
    37. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
     
    l_racher likes this.
  2. ManaCoraAus

    ManaCoraAus

    Joined:
    Sep 27, 2013
    Posts:
    2
    I've just run into this same error myself.
    In my case, it was because I was running Visual Studio 2022 (17.4.0 Preview 4.0)..
    Once I removed it and installed Visual Studio 2022 (17.3.6) I was able to build for Windows using the ILCPP scripting backend without issue.
    This is rather irksome though since I was using the preview version to access .net 7 and the associated MAUI components so it would be appreciated to have the ability to select which version of Visual Studio we'd like to use as the compiler.
     
  3. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,675
    RoyBarina likes this.
  4. unity_880B76DD9F9DB8EED3F7

    unity_880B76DD9F9DB8EED3F7

    Joined:
    Feb 14, 2022
    Posts:
    3
    This also affects Unity 2020, UWP builds & from the looks of it, Microsoft is not going to revert the change.
     
  5. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,675
    Yes, it affects all Microsoft platforms that use Visual Studio to compile code and all Unity versions.
     
  6. ManaCoraAus

    ManaCoraAus

    Joined:
    Sep 27, 2013
    Posts:
    2
    For those who are receiving this error but want to keep on using their current version of Visual Studio, Microsoft has suggested adding the following environmental variable and then restart Windows:

    Variable Name: _CL_
    Variable Value: /D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS

    I've tested this on my system using Unity 2022.1.20f1 and Visual Studio 2022 (17.4.0 Preview 5.0) and it does work.
     
  7. amit-chai

    amit-chai

    Joined:
    Jul 2, 2012
    Posts:
    80
    Life Saver!
     
  8. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,675
    Thank you so much for posting this workaround and getting the folks in this thread unblocked. I've just posted a sticky thread on our Windows subforum with a little bit less intrusive workaround: https://forum.unity.com/threads/wor...-il2cpp-with-visual-studio-2022-17-4.1355570/
     
  9. Alvarden

    Alvarden

    Joined:
    Feb 22, 2019
    Posts:
    61
    RoyBarina likes this.
  10. cataglyphis

    cataglyphis

    Joined:
    Oct 21, 2022
    Posts:
    1
    Oh my ....
    Searching in the deepest hells of the internet for this.
    Thank you so much for posting this. This is genius :)
     
    chris_ball likes this.
  11. maybeoneday35

    maybeoneday35

    Joined:
    May 17, 2021
    Posts:
    2
    Really life saver. Thanks for this
     
  12. ertbaran

    ertbaran

    Joined:
    Feb 22, 2019
    Posts:
    11
    Thanks so much. It works on my project too.
     
  13. MaoChangZingYan

    MaoChangZingYan

    Joined:
    Sep 28, 2022
    Posts:
    1
    untiy 2021.3.4f1c1
    visual Studio version 2019
    I tried all of the above without success, but after I removed vs C++ desktop development, I reinstalled it and everything was back to normal.