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:
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.
at System.Linq.Parallel.UnaryQueryOperator`2+UnaryQueryOperatorResults+ChildResultsRecipient[TInput,TOutput].Receive[TKey] (System.Linq.Parallel.PartitionedStream`2[TElement,TKey] inputStream) [0x00000] in <00000000000000000000000000000000>:0
at System.Linq.Parallel.ScanQueryOperator`1+ScanEnumerableQueryOperatorResults[TElement].GivePartitionedStream (System.Linq.Parallel.IPartitionedStreamRecipient`1[TElement] recipient) [0x00000] in <00000000000000000000000000000000>:0
at System.Linq.Parallel.UnaryQueryOperator`2+UnaryQueryOperatorResults[TInput,TOutput].GivePartitionedStream (System.Linq.Parallel.IPartitionedStreamRecipient`1[TElement] recipient) [0x00000] in <00000000000000000000000000000000>:0
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
at System.Linq.Parallel.ForAllOperator`1[TInput].RunSynchronously () [0x00000] in <00000000000000000000000000000000>:0
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):
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.
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:
ExecutionEngineException: Attempting to call method
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]
for which no ahead of time (AOT) code was generated.
This was a bug specific to this situation. In general it is still possible to have errors where the AOT code generator does not generate code used at runtime though. I’ll respond on the other thread.
Yes, I would expect that Unity 2021.3 cannot handle LINQ .AsParallel very well with IL2CPP. I would recommend moving to 2022.2 for this feature if you can.
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.
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.Expression1[TDelegate].Compile (System.Boolean preferInterpretation) [0x00000] in <00000000000000000000000000000000>:0 at System.Linq.Expressions.Expression1[TDelegate].Compile () [0x00000] in <00000000000000000000000000000000>:0
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.
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?
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.