Search Unity

IL2CPP Android build failing with Incremental Player Build failed

Discussion in 'Editor & General Support' started by joaoborlido17465, Mar 8, 2022.

  1. joaoborlido17465

    joaoborlido17465

    Joined:
    Jun 6, 2018
    Posts:
    6
    I'm having some problems with Android IL2CPP builds recently. I'm being able to perform IL2CPP builds successfully on my PC, but the same exact project is failing to build in a different PC with an error Incremental Player Build failed. I've read some reports of other people having problems similar to this as well. I even tried copying my library folder from my PC to the problematic PC but still have the same outcome. What am I doing wrong?

    Unity 2021.2.13f1
     

    Attached Files:

    Last edited: Mar 8, 2022
    Qbit86 likes this.
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Can you provide the full text of the error message?
     
  3. joaoborlido17465

    joaoborlido17465

    Joined:
    Jun 6, 2018
    Posts:
    6
    That I can! Here you go

    C:\Program Files\Unity\Hub\Editor\2021.2.13f1\Editor\Data\il2cpp\build\deploy\il2cpp.exe @Library\Bee\artifacts\rsp\13470358729104072002.rsp
    Error: IL2CPP error (no further information about what managed code was being converted is available)
    System.AggregateException: One or more errors occurred. (Value cannot be null. (Parameter 'definition'))
    ---> System.ArgumentNullException: Value cannot be null. (Parameter 'definition')
    at Unity.IL2CPP.DataModel.TypeContext.GetDef(TypeDefinition definition)
    at Unity.IL2CPP.DataModel.BuildLogic.TypeReferenceResolver.ResolveTypeReference(TypeReference typeReference, MappingContext mappingContext, CecilSourcedAssemblyData assembly)
    at Unity.IL2CPP.DataModel.BuildLogic.TypeReferenceResolver.ResolveAssemblyTypeReferences(CecilSourcedAssemblyData assembly, ReadOnlyHashSet`1 typeReferences, ReadOnlyHashSet`1 genericInstances)
    at Unity.IL2CPP.DataModel.BuildLogic.DataModelBuilder.<>c__DisplayClass14_0.<ResolveReferences>b__0(CecilSourcedAssemblyData data)
    at System.Threading.Tasks.Parallel.<>c__DisplayClass33_0`2.<ForEachWorker>b__0(Int32 i)
    at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
    --- End of stack trace from previous location ---
    at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
    at System.Threading.Tasks.TaskReplicator.Replica`1.ExecuteAction(Boolean& yieldedBeforeCompletion)
    at System.Threading.Tasks.TaskReplicator.Replica.Execute()
    --- End of inner exception stack trace ---
    at System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction`1 action, ParallelOptions options, Boolean stopOnFirstFailure)
    at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
    --- End of stack trace from previous location ---
    at System.Threading.Tasks.Parallel.ThrowSingleCancellationExceptionOrOtherException(ICollection exceptions, CancellationToken cancelToken, Exception otherException)
    at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
    at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IList`1 list, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
    at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
    at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, Action`1 body)
    at Unity.IL2CPP.DataModel.BuildLogic.Utils.ParallelHelpers.ForEach[TSource](IEnumerable`1 source, Action`1 func, Boolean enableSerial)
    at Unity.IL2CPP.DataModel.BuildLogic.DataModelBuilder.Build()
    at Unity.IL2CPP.AssemblyConversion.Phases.InitializePhase.Run(AssemblyConversionContext context)
    at Unity.IL2CPP.AssemblyConversion.Classic.ClassicConverter.Run(AssemblyConversionContext context)
    at Unity.IL2CPP.AssemblyConversion.AssemblyConverter.ConvertAssemblies(AssemblyConversionInputData data, AssemblyConversionParameters parameters, AssemblyConversionInputDataForTopLevelAccess dataForTopLevel)
    UnityEditor.GenericMenu:CatchMenu (object,string[],int)
     
    Qbit86 likes this.
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    awyld and joaoborlido17465 like this.
  5. joaoborlido17465

    joaoborlido17465

    Joined:
    Jun 6, 2018
    Posts:
    6
    I will, is there an estimate as to when I could have a solution for this problem?
     
  6. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    No, we will need to know more about the cause of the issue.
     
    joaoborlido17465 likes this.
  7. joaoborlido17465

    joaoborlido17465

    Joined:
    Jun 6, 2018
    Posts:
    6
    I submitted the report, the title is the same as this thread
     
  8. joaoborlido17465

    joaoborlido17465

    Joined:
    Jun 6, 2018
    Posts:
    6
    Any updates on this issue?
     
    Qbit86 likes this.
  9. PavelDubovik

    PavelDubovik

    Joined:
    Jun 29, 2021
    Posts:
    3
    I haven't found any issue with this name. Could you post a link please?
     
  10. PavelDubovik

    PavelDubovik

    Joined:
    Jun 29, 2021
    Posts:
    3
    About this issue. I receive same error after I added some nuget packages:

    "Microsoft.Extensions.Configuration.FileExtensions": "3.0.3",
    "Microsoft.Extensions.Configuration.Json": "3.0.3",
    "Microsoft.Extensions.Configuration.CommandLine": "3.0.3",
    "Microsoft.Extensions.Hosting": "3.0.3"

    I use Unity 2021.2.3f1
    Maybe this info helps.
     
  11. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    I have the same problem.

    @JoshPeterson Have you investigated this issue? It looks like a bug since ArgumentNullException should not be thrown, it should be prevented by some check.
    Code (csharp):
    1. System.AggregateException: One or more errors occurred. (Value cannot be null. (Parameter 'definition'))
    2. ---> System.ArgumentNullException: Value cannot be null. (Parameter 'definition')
    3.    at Unity.IL2CPP.DataModel.TypeContext.GetDef(TypeDefinition definition) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP.DataModel/TypeContext.cs:line 203
    4.    at Unity.IL2CPP.DataModel.BuildLogic.TypeReferenceResolver.ResolveTypeReference(TypeReference typeReference, MappingContext mappingContext, CecilSourcedAssemblyData assembly) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP.DataModel/BuildLogic/TypeReferenceResolver.cs:line 118
    5.    at Unity.IL2CPP.DataModel.BuildLogic.TypeReferenceResolver.ResolveAssemblyTypeReferences(CecilSourcedAssemblyData assembly, ReadOnlyHashSet`1 typeReferences, ReadOnlyHashSet`1 genericInstances) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP.DataModel/BuildLogic/TypeReferenceResolver.cs:line 47
    6.    at Unity.IL2CPP.DataModel.BuildLogic.DataModelBuilder.<>c__DisplayClass14_0.<ResolveReferences>b__0(CecilSourcedAssemblyData data) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP.DataModel/BuildLogic/DataModelBuilder.cs:line 189
    7.    at System.Threading.Tasks.Parallel.<>c__DisplayClass33_0`2.<ForEachWorker>b__0(Int32 i)
    8.    at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
    Unity Editor version: 2021.3.1f1 (3b70a0754835)
     
  12. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    Could you please share a link to the ticket so that we could track status of this bug?
     
  13. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    I don't believe that we ever got a bug report for this issue. If we did, I can't find the bug report number now.

    @Qbit86: Can you submit one?
     
  14. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
  15. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
    This error happens to me after update 2018 project to 2021 Unity and update AdMob to latest 7.0.0
    Before update AdMob all was fine, build works
    I think deleting old GoogleMobileAds.Platforms.dll helps (it not used in new AdMob and left from old version)
    (but maybe and some other old dlls)
     
  16. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    It looks like this ArgumentNullException doesn't reproduce anymore in 2021.3.4.
    But now I encounter another problem: “LLVM ERROR: out of memory”.
    It happens very often, after three hours of building (our game is huge) — but not always; sometimes build succeeds to finish after clean restart of the PC.
    I have 32 Gb of memory on my working machine, and I have never had such an issue on Unity 2018 or 2020.

    Code (csharp):
    1. Building Library\Bee\artifacts\Android\iz17e\t8m6_-CSharp216.o failed with output:
    2. LLVM ERROR: out of memory
    3. Stack dump:
    4. 0.    Program arguments: C:/Program Files/Unity/Hub/Editor/2021.3.4f1/Editor/Data/PlaybackEngines/AndroidPlayer/NDK/toolchains/llvm/prebuilt/windows-x86_64/bin\clang++.exe ... C:/Viktor/.../Library/Bee/artifacts/Android/il2cppOutput/cpp/Assembly-CSharp216.cpp
    5. 1.    <eof> parser at end of file
    6. 2.    Code generation
    7. 3.    Running pass 'Function Pass Manager' on module 'C:/Viktor/.../Library/Bee/artifacts/Android/il2cppOutput/cpp/Assembly-CSharp216.cpp'.
    8. 4.    Running pass 'ARM Assembly Printer' on function '@U4E08U4E04U4E1BU4E0FU4E07U4E19U4E03U4E1AU4E12__ctor_m58980F2D02A3AA96A065D017FD9787387049D149'
    9. #0 0x00007ff6e433fca6 C:\Program Files\Unity\Hub\Editor\2021.3.4f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe 0x4efca6 (C:\Program Files\Unity\Hub\Editor\2021.3.4f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x4efca6)
    10. #1 0x00007ff6e433fca6
    11. #2 0x00007ff6e433fca6 (C:\Program Files\Unity\Hub\Editor\2021.3.4f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x4efca6)
    12. ...
    13. #13 0x00007ffda0121881 C:\Program Files\Unity\Hub\Editor\2021.3.4f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe 0x1395 C:\Program Files\Unity\Hub\Editor\2021.3.4f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe 0x14c8
    14. #14 0x00007ffda0121881 (C:\WINDOWS\System32\ucrtbase.dll+0x71881)
    15. #15 0x00007ffda0122851 (C:\WINDOWS\System32\ucrtbase.dll+0x72851)
    16. 0x00007FF6E433FCA6 (0x000097DFDBCE0E44 0x000000A8B45FBC54 0x0000000000000016 0x00007FF6E433FCA0)
    17. 0x00007FFDA0121881 (0x00007FF6E7DE2701 0x000000A800000000 0x0000000000000000 0x000000A8B45FBCF0), raise() + 0x1E1 bytes(s)
    18. 0x00007FFDA0122851 (0x0000000200000003 0x00007FF600000003 0x000000A8B45FBD10 0x000000024329A178), abort() + 0x31 bytes(s)
    19. ...
    20. 0x00007FFDA0DD7034 (0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000), BaseThreadInitThunk() + 0x14 bytes(s)
    21. 0x00007FFDA29E2651 (0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000), RtlUserThreadStart() + 0x21 bytes(s)
    22. clang++: error: clang frontend command failed due to signal (use -v to see invocation)
    23. Android (6454773 based on r365631c2) clang version 9.0.8 (https://android.googlesource.com/toolchain/llvm-project 98c855489587874b2a325e7a516b99d838599c6f) (based on LLVM 9.0.8svn)
    24. Target: armv7a-unknown-linux-android22
    25. Thread model: posix
    26. InstalledDir: C:/Program Files/Unity/Hub/Editor/2021.3.4f1/Editor/Data/PlaybackEngines/AndroidPlayer/NDK/toolchains/llvm/prebuilt/windows-x86_64/bin
    27. clang++: note: diagnostic msg: PLEASE submit a bug report to https://github.com/android-ndk/ndk/issues and include the crash backtrace, preprocessed source, and associated run script.
    28. clang++: note: diagnostic msg:
    29. ********************
    30.  
    31. PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
    32. Preprocessed source(s) and associated run script(s) are located at:
    33. clang++: note: diagnostic msg: C:\Users\Victor\AppData\Local\Temp\Assembly-CSharp216-7e795e.cpp
    34. clang++: note: diagnostic msg: C:\Users\Victor\AppData\Local\Temp\Assembly-CSharp216-7e795e.sh
    35. clang++: note: diagnostic msg:
    36.  
    37. ********************
    38. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
    39.  
     
  17. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    This looks like an internal failure in the C++ compiler from the Android NDK. Do you know if the problem always happens in the same generated C++ method? In this error message, the method is U4E08U4E04U4E1BU4E0FU4E07U4E19U4E03U4E1AU4E12__ctor_m58980F2D02A3AA96A065D017FD9787387049D149, for example.

    If we are lucky, it will happen in that method usually, and we can inspect the generated code for that method to better understand what might be the cause.
     
  18. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    Alas, the error has occured again :(
    In 2021.3.5 on macOS, building for iOS.
    Code (csharp):
    1. Error: IL2CPP error (no further information about what managed code was being converted is available)
    2. System.AggregateException: One or more errors occurred. (Value cannot be null. (Parameter 'definition'))
    3. ---> System.ArgumentNullException: Value cannot be null. (Parameter 'definition')
    4.    at Unity.IL2CPP.DataModel.TypeContext.GetDef(TypeDefinition definition) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP.DataModel/TypeContext.cs:line 203
    5.    at Unity.IL2CPP.DataModel.BuildLogic.TypeReferenceResolver.ResolveTypeReference(TypeReference typeReference, MappingContext mappingContext, CecilSourcedAssemblyData assembly) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP.DataModel/BuildLogic/TypeReferenceResolver.cs:line 118
    6.    at Unity.IL2CPP.DataModel.BuildLogic.TypeReferenceResolver.ResolveAssemblyTypeReferences(CecilSourcedAssemblyData assembly, ReadOnlyHashSet`1 typeReferences, ReadOnlyHashSet`1 genericInstances) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP.DataModel/BuildLogic/TypeReferenceResolver.cs:line 47
    7.    at Unity.IL2CPP.DataModel.BuildLogic.DataModelBuilder.<>c__DisplayClass14_0.<ResolveReferences>b__0(CecilSourcedAssemblyData data) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP.DataModel/BuildLogic/DataModelBuilder.cs:line 189
    8.    at System.Threading.Tasks.Parallel.<>c__DisplayClass33_0`2.<ForEachWorker>b__0(Int32 i)
    9.    at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
     
    unity_EXf3EldqEIsgag and Petr777 like this.
  19. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
  20. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    This does look very much like the issue you linked to. I'm trying to track down the fix for this issue to determine if we can back port it.

    To make sure we have all of the details, can you submit a bug report for this issue against Unity 2021.3?
     
    awyld likes this.
  21. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    awyld likes this.
  22. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    awyld likes this.
  23. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    One more question - is this a consistent failure, or does it happen on sometimes?
     
  24. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    Hard to say.
    At first it consistently failed on Unity 2021.3.1 on my Windows machine building for Android.
    Later I updated to Unity 2021.3.4, and this seemed to work out, build finally succeeded (although some attempts failed with “LLVM ERROR: out of memory”).
    But after that we've set up Unity 2021.3.5 on dedicated macOS machine, and this IL2CPP error returned on building for both Android and iOS.
     
  25. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Thanks for the details - we will investigate this.
     
    Petr777 likes this.
  26. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    Petr777 likes this.
  27. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    No, I'm not quite sure what the status of this bug report is. I'll check in with our QA team to try to determine what is happening.
     
    Petr777 and Qbit86 like this.
  28. Petr777

    Petr777

    Joined:
    Nov 8, 2017
    Posts:
    49
    Are there any news on this bug? We have it on 2021.3.7.
    Thank you!
     
    awyld and Qbit86 like this.
  29. Petr777

    Petr777

    Joined:
    Nov 8, 2017
    Posts:
    49
    @JoshPeterson Can you tell us please are there any docs for il2cpp command line arguments?
    We think we can try to avoid this error by experimenting with
    Code (CSharp):
    1.  --code-generation-option=<value>                Specify an option related to code generation
    2.   --generics-option=<value>                       Specify an option related to generics
    3.   --feature=<value>                               Enable a feature of il2cpp
    4.   --diagnostic-option=<value>                     Enable a diagnostic ability
    command line options.
    But we need to know possible values for this option
     
  30. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    awyld, Qbit86 and Petr777 like this.
  31. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    We don't document those command line arguments because they change release to release of Unity. They are intended for internal use by the Unity editor in most cases.

    I do believe that the code generation option might help here though. In Unity 2021 LTS you can change that using the IL2CPP Code Generation option in the Build Settings window. Try the "Faster (smaller) builds" option. That will enable full generic sharing, which will share implementations for all generic types (including generics with value type generic arguments). That will often decrease the code size.
     
    rimkchouic and Petr777 like this.
  32. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    Do you have any estimates on when the fix will be available? The status states “Fix In Review for 2021.3.9f1” [1], and it's been a while since the last release of 2021.3.8f1 on 9 Aug [2].

    [1] https://issuetracker.unity3d.com/is...r-when-building-in-il2cpp-scripting-backend-1

    [2] https://unity3d.com/get-unity/download/archive
     
  33. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    yuliyF and Qbit86 like this.
  34. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    I keep F5'ing “Unity download archive” page :) Any updates on rescheduling?
     
    plotlessplot likes this.
  35. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,260
     
  36. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Sorry, I'm not involved in the release process - I was looking at our internal release calendar. Hopefully it will be out soon.
     
    Petr777 and Qbit86 like this.
  37. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    2021.3.9f1 doesn't fix the issue. It still throws an `ArgumentNullException` inside `Unity.IL2CPP.DataModel.dll`.
    Code (csharp):
    1. System.ArgumentNullException: Value cannot be null. (Parameter 'definition')
    2.    at Unity.IL2CPP.DataModel.TypeContext.GetDef(TypeDefinition definition)
    3.    at Unity.IL2CPP.DataModel.BuildLogic.TypeReferenceResolver.ResolveTypeReference(TypeReference typeReference, MappingContext mappingContext, CecilSourcedAssemblyData assembly)
    4.    at Unity.IL2CPP.DataModel.BuildLogic.TypeReferenceResolver.ResolveAssemblyTypeReferences(CecilSourcedAssemblyData assembly, ReadOnlyHashSet`1 typeReferences, ReadOnlyHashSet`1 genericInstances)
    5.    at Unity.IL2CPP.DataModel.BuildLogic.DataModelBuilder.<>c__DisplayClass15_0.<ResolveReferences>b__0(CecilSourcedAssemblyData data)
    6.    at System.Threading.Tasks.Parallel.<>c__DisplayClass33_0`2.<ForEachWorker>b__0(Int32 i)
    7.    at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
     
    Petr777 likes this.
  38. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    What I'm currently struggling with is rebuilding disassembled and fixed code of Unity.IL2CPP.DataModel.dll.
    Both dotPeek and dnSpy generate code that fails to build due to some infrastructure issues (build tools, target framework version, BCL version). Please let me know if anyone manages to build a patched version.
    My guess of what is going on here is that `typeReference.Resolve()` implementation (indirectly calling `IMetadataResolver.Resolve(TypeReference type)`) can legitimately return `null`, while `TypeContext.GetDef(TypeDefinition definition)` has non-null `definition` as its precondition contract.
     

    Attached Files:

    Petr777 likes this.
  39. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    I'm not sure why this was not corrected - we're following up now. I'll report more when we have more details.
     
    Petr777 likes this.
  40. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    ILSpy did the work, it managed to decompile the assembly to a buildable (after a little fix) C# 9 code.

    Looks like my fix was successful (see attached screenshot), at least build doesn't fail anymore. So I'm able to proceed with patched Unity.IL2CPP.DataModel.dll. (Probably illegal and absolutely cursed, but what else can I do with vendor lock?)
     

    Attached Files:

    Petr777 likes this.
  41. mike-voorhees

    mike-voorhees

    Unity Technologies

    Joined:
    Aug 9, 2016
    Posts:
    46
    The most probable cause of this ArgumentNullException is invalid IL. There are 2 ways I have seen this error triggered recently

    1) Our unresolved stubbing code that runs during Managed Code Stripping had a bug that result in invalid IL and would trigger this ArgumentNullException. That was this issue https://issuetracker.unity3d.com/is...ror-when-building-in-il2cpp-scripting-backend and that has been fixed. I rechecked the project with 2021.3.9f1 and it builds successfully. Note that this unresolved stubbing code is itself trying to patch up invalid IL. It's not realistic to correctly patch all possible invalid IL, but Unity has attempted to patch up simple cases for ages so we continue to maintain this logic. I'll circle back to this.

    2) Our internal unit tests were tripped by this fun bug in .NET Core https://github.com/dotnet/runtime/issues/70742. That bug in .NET Core resulted in our test passing an assembly compiled against the .NET Core to our Data Model to load. And it would trigger this same exception. I'm not sure if there is a plausible way for a Unity build to run into the fundamental problem here. It is certainly plausible that someone puts an assembly compiled against .NET Core into their project. However, I suspect something else would error before we reached this Data Model code. Never the less, it's worth keeping in mind.

    Circling back to https://issuetracker.unity3d.com/is...ror-when-building-in-il2cpp-scripting-backend. When I looked into that issue I did some digging to see why that project had invalid IL that triggered Managed Code Stripping to try and patch up the IL. That led me to Odin Inspector.

    Odin Inspector will scan the assemblies that were compiled against the Editor looking for types that match some pattern. It will then generate an assembly called Sirenix.Serialization.AOTGenerated.dll that will contain a method called PreventCodeStrippingViaReferences. In this method they generate code to create instances of the types they saw in the assemblies compiled against the Editor. This problem with this scheme is that a user can define a type inside a #if. For example
    Code (CSharp):
    1. #if UNITY_EDITOR
    2. public class Foo
    3. {
    4. }
    5. #endif
    When the assemblies are compiled for the player build, Foo will not exist. However, Sirenix.Serialization.AOTGenerated.dll will contain a
    Code (CSharp):
    1. new Foo();
    That is invalid IL. UnityLinker (The tool that performs Managed Code Stripping) see's this invalid IL and tries to patch up the IL by creating the type Foo with a default constructor. Our bug that resulted in https://issuetracker.unity3d.com/is...ror-when-building-in-il2cpp-scripting-backend was due to a little nuance of how type references are created.

    The bug that you filed https://fogbugz.unity3d.com/default.asp?1426932_ponvh8b68h1njhqg , didn't have a project but it had the same exception as https://issuetracker.unity3d.com/is...ror-when-building-in-il2cpp-scripting-backend and so we thought it was a duplicate.

    I'm now suspecting your project triggers a different bug or has some other invalid IL that we simply can't recover from.

    Awhile back when I discovered (2) above I put in a better error message that includes information about the TypeReference that couldn't be resolved in the exception message. I didn't backport that at the time, but I will now. One path forward would be to wait for this change and see if the improved error can help you find the problematic code. Then you may be able to fix it yourself or narrow down a repro project to submit with a bug.

    Another option would be to check if you are using Odin Inspector or have anything in your project that does something similar to what I described about Odin Inspector.

    You've mentioned that you cannot include your project in a bug report. There is another option if you are comfortable submitting your managed assemblies with a bug report. To do this you would need to turn on some diagnostics.

    Under Editor->Preferences there is a section on the left called Diagnostics. Then on the right you want to expand the group Editor. Then look for the field VMUnityLinkerAdditionalArgs. In that field add

    --enable-report --enable-snapshot


    Then do a player build that triggers the exception.

    After the player build fails, navigate to "%TEMP%\UnityLinker\Snapshots" or on macOS "$TMPDIR/UnityLinker/Snapshots"

    Each time you do a player build a new folder will be created in that directory. Zip up the contents of the folder and submit it with a bug report.

    When you are done, go back and clear the VMUnityLinkerAdditionalArgs field. That setting will persist and you don't want that set all the time.

    If you would prefer not to submit your assemblies with the bug report, you could try and use these diagnostics to find the problem yourself. For best results you'd probably want to do this on Windows. Although it should work on macOS if you have an official mono install on your system.

    You'll want to go back to VMUnityLinkerAdditionalArgs and add another command line option

    --enable-ildump


    Note that with this option set your player build will take longer.

    Do another player build and then go back to the Snapshots directory again. Open the most recently created folder and inside there will be a directory called "inputs". Look at every file named "*.verify.stdout" and see if anything jumps out. Using the other bug report as an example, what I saw was

    [IL]: Error: [C:\Users\Mike\AppData\Local\Temp\UnityLinker\Snapshots\2022-09-07-16-40-56-yo0z00mucbo\input\Sirenix.Serialization.AOTGenerated.dll : Sirenix.Serialization.AOTGenerated.PreventCodeStrippingViaReferences::.cctor][offset 0x00000388] Unable to resolve token.


    If you see any errors like that, that's a sign that the assemblies being used in the player build contain invalid IL. You can try and find and fix the issue yourself. Or you can use this information to try and narrow down the minimum code necessary to trigger the exception so that you can submit a bug report.

    Hopefully we can get to the bottom of this.

    Thanks,
    -Mike
     
    Petr777 and Qbit86 like this.
  42. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    @mike-voorhees Thank you so much for the reply! (And @JoshPeterson for letting you know about my problem, if it was him.)
    This is the most detailed comment I've seen on the forum so far, I really appreciate your efforts.

    Then I'm looking forward to 2021.3.10 to try it with enhanced error messages. Hopefully this will help narrow down the obscure issue.
    As for the rest of the suggestions, I will have to re-read the post in the morning and figure out what diagnostics I can apply.

    Thanks again!
     
    Petr777 likes this.
  43. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    Well, I didn't have the patience to wait, so I fixed the call to GetDef() in TypeReferenceResolver by throwing an exception, capturing the type in error message (see screenshot).
    Now IL2CPP complains about the type `UnityEngine.BlendWeights`. We don't use it explicitly in our codebase. It's marked as obsolete in 2021.3.9 and the documentation for it [1] is not available anymore.

    Code (csharp):
    1. System.InvalidOperationException: Failed to determine type. type: Mono.Cecil.TypeReference, typeReference: UnityEngine.BlendWeights
    2.    at Unity.IL2CPP.DataModel.BuildLogic.TypeReferenceResolver.<ResolveTypeReference>g__ThrowInvalidTypeReference|8_0(TypeReference typeReference)
    3.    at Unity.IL2CPP.DataModel.BuildLogic.TypeReferenceResolver.ResolveTypeReference(TypeReference typeReference, MappingContext mappingContext, CecilSourcedAssemblyData assembly)
    4.    at Unity.IL2CPP.DataModel.BuildLogic.TypeReferenceResolver.ResolveAssemblyTypeReferences(CecilSourcedAssemblyData assembly, ReadOnlyHashSet`1 typeReferences, ReadOnlyHashSet`1 genericInstances)
    5.    at Unity.IL2CPP.DataModel.BuildLogic.DataModelBuilder.<>c__DisplayClass15_0.<ResolveReferences>b__0(CecilSourcedAssemblyData data)
    6.    at System.Threading.Tasks.Parallel.<>c__DisplayClass33_0`2.<ForEachWorker>b__0(Int32 i)
    7.    at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)

    [1] https://docs.unity3d.com/2018.4/Documentation/ScriptReference/BlendWeights.html
     

    Attached Files:

    Petr777 likes this.
  44. herzogs

    herzogs

    Joined:
    Aug 10, 2022
    Posts:
    6
    @mike-voorhees I'm more of a silent reader but I just send a Bug Report with the Snapshot attached as a .7z file. Hope this helps solve this error!

    Btw also big thanks to @Qbit86 for posting so many infos here!
     
  45. mike-voorhees

    mike-voorhees

    Unity Technologies

    Joined:
    Aug 9, 2016
    Posts:
    46
    Your change looks functionaly equivalent to the change I backported the other day. So the error about UnityEngine.BlendWeights should be accurate.

    I found a couple interesting things poking around `UnityEngine.BlendWeights`. But I wasn't able to put together a complete workflow that triggers the NullReferenceException.

    1) UnityLinker cannot correctly stub in a missing enum. If a TypeReference was found to an enum and that failed to resolve, UnityLinker will recreate the type as a struct. This isn't great, but creating a struct does mean that the type reference would at least resolve. Something else would probably fail later during the il2cpp.exe conversion process.

    2) I can't get Unity to let me build with a script that references BlendWeights. The API updater insists on updating it.

    3) When I use a link.xml to preserve all of UnityEngine.CoreModule.dll (where UnityEngineBlendWeights is defined), I can build with IL2CPP successfully.

    4) `UnityEngine.BlendWeights` is stripped out of an empty project.

    5) In ILSpy, dnSpy, etc, if you look at the `UnityEngine.dll` for the player build in your install, for example `Data\PlaybackEngines\AndroidPlayer\Variations\il2cpp\Managed\UnityEngine.dll`. You will see there is an internal BlendWeights enum defined.


    namespace UnityEngine
    {
    // Token: 0x02000002 RID: 2
    internal enum BlendWeights
    {
    }
    }



    This is strange. I don't know how or why this is here. I'm asking around. That said, I haven't found an easy way to make this cause a problem. MAYBE if you somehow had a TypeReference appear in the IL that pointed to [UnityEngine]UnityEngine.BlendWeights. MAYBE that could lead to a GetDef error. That theory would be time consuming to test. And it would require a number of things to hold together and make it to il2cpp. Namely, UnityLinker's stubbing code.

    6) I was able to use a link.xml to preserve the empty BlendWeights in UnityEngine.dll, while the real BlendWeights in UnityEngine.CoreModule.dll was stripped away. This is a weird situation, but I don't see a way to get this to lead to a NullReferenceException from GetDef.

    It seems plausible you are hitting a reference to `UnityEngine.BlendWeights` that is unresolvable. But my odds of guessing how you are ending up in that situation based on only the type name are not great. I need more information if you want to get to the bottom of it.

    I'll offer you some ideas on things to explore.

    * Do you have any precompiled assemblies? Any that could contain references to BlendWeights?

    * Is there anything modifying the IL of the assemblies?

    * Was this project upgraded from a release before BlendWeights was made obsolete?

    * Going back to my previous post when I suggested trying `--enable-report --enable-snapshot --enable-ildump`. Do that, and then search the snapshot directory for `BlendWeights`. This will show you all of the places in the IL that reference BlendWeights. The .il files will show you references in the IL.

    * In your changes to the DataModel assembly to throw a better error, try adding `{assembly.Assembly.Source.Name.Name}` into the exception message. This will at least tell you what assemblies the bad TypeReference is in (I will make this change in our code now that I see the TypeReference name alone doesn't get you very far)

    I'm happy to take a closer look, but I'm going to need more information. If you are worried about what assemblies you submit with a bug report you can delete any files that you don't want to submit from the snapshot directory I mentioned in my last post. Just keep in mind, the more you delete, the less likely I'll be able to trace back to the source of the problem.
     
    Last edited: Sep 9, 2022
    Petr777 and Qbit86 like this.
  46. mike-voorhees

    mike-voorhees

    Unity Technologies

    Joined:
    Aug 9, 2016
    Posts:
    46
    Thanks. I will hunt it down and take a look.
     
  47. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    Unfortunately we do have, a lot of them, different third-party plugins.

    Yes, the current version of our game in production is still built with Unity 2018.4. Which is too old, and we have to move to 2021.3 (via 2020).

    Thanks for suggestion, I've implemented it (see screenshot attached), this gives the name of the suspect: third party assembly Assets/Plugins/DecalSystem.Runtime.dll:
    Code (csharp):
    1.  ---> System.InvalidOperationException: Failed to determine type. typeReference: UnityEngine.BlendWeights, assembly: DecalSystem.Runtime
    2.    at Unity.IL2CPP.DataModel.BuildLogic.TypeReferenceResolver.<>c__DisplayClass8_0.<ResolveTypeReference>g__ThrowInvalidTypeReference|0()
    3.    at Unity.IL2CPP.DataModel.BuildLogic.TypeReferenceResolver.ResolveTypeReference(TypeReference typeReference, MappingContext mappingContext, CecilSourcedAssemblyData assembly)
    4.    at Unity.IL2CPP.DataModel.BuildLogic.TypeReferenceResolver.ResolveAssemblyTypeReferences(CecilSourcedAssemblyData assembly, ReadOnlyHashSet`1 typeReferences, ReadOnlyHashSet`1 genericInstances)
    5.    at Unity.IL2CPP.DataModel.BuildLogic.DataModelBuilder.<>c__DisplayClass15_0.<ResolveReferences>b__0(CecilSourcedAssemblyData data)
    6.    at System.Threading.Tasks.Parallel.<>c__DisplayClass33_0`2.<ForEachWorker>b__0(Int32 i)
    7.    at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
     

    Attached Files:

    Petr777 likes this.
  48. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    Ok, I've managed to get minimalistic repro for the invalid IL — please see the project attached in zip-archive. It's basically an empty project with a scene and a script, and an assembly DecalSystem.Runtime.dll copied from our game. The library is quite outdated and is built against the old version of Unity (references the old UnityEngine.dll).
    You should reject API Updater in order to reproduce the problem.
    Please let me know if you are able to reproduce the exception; feel free to attach the project to the ticket.

    By the way, how can I run API updater manually? There used to be “Run API Updater...” command in “Assets” menu; but it is not there anymore in 2021.3.9.
     

    Attached Files:

    Last edited: Sep 12, 2022
    Petr777 likes this.
  49. mike-voorhees

    mike-voorhees

    Unity Technologies

    Joined:
    Aug 9, 2016
    Posts:
    46
    If you Reimport the asset for DecalSystem.Runtime.dll you will get the prompt to run the API updater again.

    I was able to reproduce the exception.

    I'm tempted to say that in the case of your project, there is not a bug. The API Updater needs to run on DecalSystem.Runtime.dll. The popup dialog reporting that the API Updater needs to run on DecalSystem.Runtime.dll states that choosing not to let the API Updater run will likely lead to failures at runtime or load time. The message doesn't explicitly mention "build time" failures, but I think the gist of the message is clear "things are probably not going to work".

    After letting the API updater run, your repro project builds successfully.

    If you don't mind me asking, was there a reason you didn't let the API updater run when you first opened the project? Is there something blocking you from letting it run? Is it a lack of trust in what the API updater will do? I'd like to understand if there is anything we can do to improve the workflow.

    I do see how the error that you hit is not helpful at all.

    I've improved the error message going forward. Now the error message will include the assembly name as well. That will help connect the dots in some cases.

    I'm going to follow up on this internal BlendWeights enum in UnityEngine.dll. We do this instead of add a type forwarder when a type has Obsolete error=true. I suspect DecalSystem.Runtime.dll could have held together if we had the type forwarder instead. But I don't know the design intent behind this scheme so I can't promise anything will change.

    I can ask around about forcing precompiled assemblies to be updated before doing a player build. On one hand this would be consistent with trying to use an Obsolete error type from a script. I couldn't get a player build to run with "BlendWeights" appearing in a script. On the other hand, users may not like being forced to update the precompiled assemblies. Again, no promises anything will change on this front. There may be reasons why the workflow is the way it is.

    Thanks for the helping to get to the bottom of this.
    -Mike
     
  50. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    Well, ArgumentNullException is definitely a bug — it's a contract violation inside library code, it always denotes a _logical_ error.
    Appropriate type of runtime exception (specific one or at least InvalidOperationException with helpful message) can denote a _usage_ error.

    I don't remember exactly why I didn't run API Updater, and in what circumstances I discarded the dialog. The process of migration on latest LTS version of Unity is extended over time, several months.
    When I skipped API-updating before, it didn't led to obscure build error. And I'm always aware that skipping API-updating may result in runtime failures when third party assembly calls some rarely used removed API.

    ...But once I discarded it, the dialog never appeared again. If I saw it I would consider updating or at least payed attention to that particular assembly.

    Sorry to say that, but _of course_ I do not trust the compiled assembly rewriter :)
    When API Updater touches the source code, at least I can see in diff viewer what changes it proposes.
    But when it suggests rewriting dll's and all I see is changed blob in git?
    What if third party library uses reflection or adds defense against binary tampering like checking signature?

    Maybe hard versioning or strong-naming the assemblies like UnityEngine.dll, in order to enforse reference correctness.

    Thanks a lot, that will really help.

    Probably it's not worth digging into this particular type any further. The root of the issue is known — rejected API Updater. If there are clues suggesting re-importing an assembly and (re-)running API Updater, that would likely be enough.

    Absolutely agree, this shouldn't be mandatory. There are risks on both sides.

    Absolutely. Like Chesterton's Fence