Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

No ahead of time (AOT) code was generated

Discussion in 'Windows' started by wahntin, Mar 6, 2021.

  1. wahntin

    wahntin

    Joined:
    Sep 17, 2019
    Posts:
    83
    Hi,
    I'm currently trying to update from Unity 2019.4 to 2020.2. Editor is running fine, but I face a problem when trying to run the game after the IL2CPP build.

    The error I get is as follows:

    Code (csharp):
    1. ExecutionEngineException: Attempting to call method 'System.Linq.Parallel.ForAllOperator`1<ImagineEarth.Logic.FactionSimulation>::WrapPartitionedStream<System.Int32>' for which no ahead of time (AOT) code was generated.
    2.   at System.Linq.Parallel.UnaryQueryOperator`2+UnaryQueryOperatorResults+ChildResultsRecipient[TInput,TOutput].Receive[TKey] (System.Linq.Parallel.PartitionedStream`2[TElement,TKey] inputStream) [0x00000] in <00000000000000000000000000000000>:0
    3.   at System.Linq.Parallel.ScanQueryOperator`1+ScanEnumerableQueryOperatorResults[TElement].GivePartitionedStream (System.Linq.Parallel.IPartitionedStreamRecipient`1[TElement] recipient) [0x00000] in <00000000000000000000000000000000>:0
    4.   at System.Linq.Parallel.UnaryQueryOperator`2+UnaryQueryOperatorResults[TInput,TOutput].GivePartitionedStream (System.Linq.Parallel.IPartitionedStreamRecipient`1[TElement] recipient) [0x00000] in <00000000000000000000000000000000>:0
    5.   at System.Linq.Parallel.QueryOperator`1[TOutput].GetOpenedEnumerator (System.Nullable`1[T] mergeOptions, System.Boolean suppressOrder, System.Boolean forEffect, System.Linq.Parallel.QuerySettings querySettings) [0x00000] in <00000000000000000000000000000000>:0
    6.   at System.Linq.Parallel.ForAllOperator`1[TInput].RunSynchronously () [0x00000] in <00000000000000000000000000000000>:0
    It seems not to be possible to deactivate code stripping, as documented here: https://docs.unity3d.com/Manual/ManagedCodeStripping.html

    So I tried to user a link.xml file, but it doesn't make a difference and I'm not sure what might be wrong (for now I've only tried the brute force approach):

    Code (csharp):
    1.  
    2. <linker>
    3.   <assembly fullname="mscorlib" preserve="all"/>
    4.   <assembly fullname="netstandard" preserve="all"/>
    5.   <assembly fullname="System" preserve="all"/>
    6.   <assembly fullname="System.Linq" preserve="all"/>
    7.   <assembly fullname="System.Linq.Parallel" preserve="all"/>
    8.   <assembly fullname="System.Linq.Queryable" preserve="all"/>
    9. </linker>
    10.  
    I have tried to put the file in the main Assets folder and also into the Scripts sub-folder. Both doesn't make a difference.

    Any ideas?
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,801
    The error about "No ahead of time (AOT) code was generated" is unrelated to to managed code stripping. Instead, it means that the code uses some generics with value types that IL2CPP cannot find at compile time, and therefore does not generate code for.

    However, did this same project work with 2019.4? If so, this is likely a bug in IL2CPP that we would like to fix immediately.
     
  3. wahntin

    wahntin

    Joined:
    Sep 17, 2019
    Posts:
    83
    Yes, it does work with 2019.4. When moving to 2020.2 the only thing I had to change was updating some shaders, so the related code has not changed.

    The call that fails is:
    Code (CSharp):
    1. dictionary.Values.AsParallel().ForAll(element => element.MethodCall());
     
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,801
    Huh, it seems very odd that would fail in a newer version of Unity. Can you submit a bug report? https://unity3d.com/unity/qa/bug-reporting
     
  5. wahntin

    wahntin

    Joined:
    Sep 17, 2019
    Posts:
    83
    Done. ID is 1320295
     
    JoshPeterson likes this.
  6. MTeplytskyi

    MTeplytskyi

    Joined:
    Jun 16, 2020
    Posts:
    26
    Hi! Have the same problem, any ways how to fix this?
     
  7. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,801
    We have nothing to report yet, our QA team is still looking at this.
     
  8. rebelalliancedev

    rebelalliancedev

    Joined:
    Nov 20, 2019
    Posts:
    1
    Hi, I have a similar error (only in IL2CPP build) that we can replicate in 2020.3.6 LTS.

    The error is not related to
    System.Linq.Parallel.ForAllOperator
    but it is related to the use of
    System.Reactive


    The same code worked fine in 2019.4 LTS.

    The error I get is:

    Code (Log):
    1. ExecutionEngineException: Attempting to call method
    2. System.Reactive.Concurrency.CurrentThreadScheduler::Schedule<System.ValueTuple`2[[System.Action`1[[System.Reactive.AutoDetachObserver`1[[System.Collections.Generic.IEnumerable`1[[RebelAlliance.BusinessLogic.IEntity, com.rebelalliance.ss4.businesslogic, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], System.Reactive, Version=4.4.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]
    3. for which no ahead of time (AOT) code was generated.
    It seems that the issue https://issuetracker.unity3d.com/is...alling-linq-dot-parallelenumerable-dot-forall has been solved in 2020.3.X but maybe it is a different bug.
     
  9. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,801
    This will be corrected in 2020.3.7, which should be released soon.
     
  10. MTeplytskyi

    MTeplytskyi

    Joined:
    Jun 16, 2020
    Posts:
    26
  11. jmgek

    jmgek

    Joined:
    Dec 9, 2012
    Posts:
    90
  12. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,801
  13. dylan_unity623

    dylan_unity623

    Joined:
    Nov 3, 2022
    Posts:
    1
  14. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,801
  15. CWatsonT2

    CWatsonT2

    Joined:
    Jan 9, 2019
    Posts:
    114
    I'm having the same problem I think. I'm doing a UnityWebRequest and it works just fine with the mono backend but when I change it to il2cpp it crashes at the UnityWebRequest. I'm in unity 2021.3.16.1. I tried 2022.1.20 and 2022.2.8 with the same issue.

    *FIXED In my case it's SimpleJSON that doesn't work with il2cpp. I switched to Newtonsoft and it is working fine.
     
    Last edited: Feb 26, 2023
    JoshPeterson likes this.
  16. ViacheslavRud

    ViacheslavRud

    Joined:
    Aug 1, 2018
    Posts:
    19
    Hello. I have a related issue when I use FluentValidation. Unity 2021.3.25f

    ExecutionEngineException: Attempting to call method 'System.Linq.Expressions.Interpreter.LightLambda::MakeRun1<MyType,System.Int32>' for which no ahead of time (AOT) code was generated.
    at System.Linq.Expressions.Interpreter.LightLambda.MakeDelegate (System.Type delegateType) [0x00000] in <00000000000000000000000000000000>:0
    at System.Linq.Expressions.Interpreter.LightDelegateCreator.CreateDelegate (System.Runtime.CompilerServices.IStrongBox[] closure) [0x00000] in <00000000000000000000000000000000>:0
    at System.Linq.Expressions.Interpreter.LightDelegateCreator.CreateDelegate () [0x00000] in <00000000000000000000000000000000>:0
    at System.Linq.Expressions.Expression`1[TDelegate].Compile (System.Boolean preferInterpretation) [0x00000] in <00000000000000000000000000000000>:0
    at System.Linq.Expressions.Expression`1[TDelegate].Compile () [0x00000] in <00000000000000000000000000000000>:0
     
  17. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,801
    The Linq expression interpreter won't work too well with Unity 2021.3 and IL2CPP. If you need to use it, I would recommend Unity 2022.2 and later, where IL2CPP can better handle generics that it cannot discover at compile time.
     
    RoyBarina and ViacheslavRud like this.
  18. Reimirno7

    Reimirno7

    Joined:
    Nov 25, 2021
    Posts:
    51
    Thanks for the heads up.

    Bumped into this issue today (2021.3.27f1) and the issue arises frm LINQing on a valuetuple type. Replace LINQ with foreach loop and issue resolved.

    Unfortunately for us it is not feasible to do a major version upgrade. It would be of great help if you can provide more info on this bug. Under what condition would LINQ +Generics cause problem for IL2CPP?
     
  19. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,801
    LINQ in general is fine, but the LINQ expression interpreter will lead to problems. Those problems can occur when the expression interpreter uses value types as generic arguments that IL2CPP did not see at compile time. Unfortunately it is often difficult to determine when a problem will occur, because it is not clear from the source code what generic types the LINQ expression interpreter will use.

    I think the best option it to avoid using the LINQ expression interpreter.
     
  20. Thatworkspace

    Thatworkspace

    Joined:
    Oct 25, 2020
    Posts:
    1



    Hello there! we're getting this error on our Android build (not happenin' on editor)!

    ScriptingBackend: IL2CPP
    UnityVersion: 2021.3.19f1 LTS

    07-28 15:21:03.070: E/Unity(12583): ExecutionEngineException: Attempting to call method 'System.Reactive.Concurrency.CurrentThreadScheduler::Schedule<System.ValueTuple`2[[System.Action`1[[System.ValueTuple`2[[System.Reactive.Producer`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Reactive.Linq.ObservableImpl.AsObservable`1+_[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], System.Reactive, Version=5.0.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263]], System.Reactive, Version=5.0.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263],[System.Reactive.Linq.ObservableImpl.AsObservable`1+_[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], System.Reactive, Version=5.0.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.ValueTuple`2
     
  21. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,801
    This is the kind of error that can happen with IL2CPP and the LINQ expression interpreter. If you must use the expression interpreter, I would recommend you move to Unity 2022 versions. In that release we have worked around this problem, and removed the possibility of this class of error from happening entirely.