Search Unity

Bug Processing Assemby, ILPostProcessor exception: System.ArgumentNullException: Value cannot be null

Discussion in 'Entity Component System' started by Mockarutan, Sep 30, 2022.

  1. Mockarutan

    Mockarutan

    Joined:
    May 22, 2011
    Posts:
    159
    I tried starting to convert my project to the new 1.0 exp release, and when I got rid of all compilation errors I got this error. I have no idea where to look since it's totally anonyms as far as I can tell. Anyone seen this or know what it is?

    Processing assembly Library/Bee/artifacts/1900b0aE.dag/Assembly-CSharp.dll, with 129 defines and 384 references
    processors: Unity.Entities.CodeGen.EntitiesILPostProcessors, Unity.Jobs.CodeGen.JobsILPostProcessor, zzzUnity.Burst.CodeGen.BurstILPostProcessor
    running Unity.Entities.CodeGen.EntitiesILPostProcessors
    running Unity.Jobs.CodeGen.JobsILPostProcessor
    Unity.Jobs.CodeGen.JobsILPostProcessor: ILPostProcessor has thrown an exception: System.ArgumentNullException: Value cannot be null.
    at Mono.Cecil.MetadataBuilder.LookupToken(IMetadataTokenProvider provider)
    at Mono.Cecil.Cil.CodeReader.PatchRawCode(ByteBuffer buffer, Int32 code_size, CodeWriter writer)
    at Mono.Cecil.Cil.CodeReader.PatchRawFatMethod(ByteBuffer buffer, CodeWriter writer, Int32& code_size, MetadataToken& local_var_token)
    at Mono.Cecil.Cil.CodeReader.PatchRawMethodBody(MethodDefinition method, CodeWriter writer, Int32& code_size, MetadataToken& local_var_token)
    at Mono.Cecil.Cil.CodeWriter.WriteUnresolvedMethodBody(MethodDefinition method)
    at Mono.Cecil.Cil.CodeWriter.WriteMethodBody(MethodDefinition method)
    at Mono.Cecil.MetadataBuilder.AddMethod(MethodDefinition method)
    at Mono.Cecil.MetadataBuilder.AddMethods(TypeDefinition type)
    at Mono.Cecil.MetadataBuilder.AddType(TypeDefinition type)
    at Mono.Cecil.MetadataBuilder.AddTypes()
    at Mono.Cecil.MetadataBuilder.BuildTypes()
    at Mono.Cecil.MetadataBuilder.BuildModule()
    at Mono.Cecil.MetadataBuilder.BuildMetadata()
    at Mono.Cecil.ModuleWriter.<>c.<BuildMetadata>b__2_0(MetadataBuilder builder, MetadataReader _)
    at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func`3 read)
    at Mono.Cecil.ModuleWriter.BuildMetadata(ModuleDefinition module, MetadataBuilder metadata)
    at Mono.Cecil.ModuleWriter.Write(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
    at Mono.Cecil.ModuleWriter.WriteModule(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
    at Unity.Jobs.CodeGen.JobsILPostProcessor.Process(ICompiledAssembly compiledAssembly)
    at Unity.ILPP.Runner.PostProcessingPipeline.PostProcessAssemblyAsync(PostProcessAssemblyRequest request, Action`2 progressSink)
    PostProcessing failed
    Unhandled Exception: System.InvalidOperationException: Post processing failed
    at Unity.ILPP.Trigger.TriggerApp.<ProcessArgumentsAsync>d__1.MoveNext() + 0xa2d
    --- End of stack trace from previous location ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x20
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xb6
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x42
    at Unity.ILPP.Trigger.TriggerApp.<RunAsync>d__0.MoveNext() + 0xdc
    --- End of stack trace from previous location ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x20
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xb6
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x42
    at Program.<<Main>$>d__0.MoveNext() + 0x153
    --- End of stack trace from previous location ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x20
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xb6
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x42
    at Program.<Main>(String[]) + 0x20
    at Unity.ILPP.Trigger!<BaseAddress>+0x58bc7f
     
  2. tawi1

    tawi1

    Joined:
    Feb 19, 2017
    Posts:
    17
    I got the same error with my dll:
    Processing assembly Library/Bee/artifacts/1900b0aEDbg.dag/DotsCityEntities.dll, with 130 defines and 257 references
    processors: Unity.Entities.CodeGen.EntitiesILPostProcessors, Unity.Jobs.CodeGen.JobsILPostProcessor, zzzUnity.Burst.CodeGen.BurstILPostProcessor
    running Unity.Entities.CodeGen.EntitiesILPostProcessors
    running Unity.Jobs.CodeGen.JobsILPostProcessor
    Unity.Jobs.CodeGen.JobsILPostProcessor: ILPostProcessor has thrown an exception: System.ArgumentNullException: Value cannot be null.
    at Mono.Cecil.MetadataBuilder.LookupToken(IMetadataTokenProvider provider)
    at Mono.Cecil.Cil.CodeReader.PatchRawCode(ByteBuffer buffer, Int32 code_size, CodeWriter writer)
    at Mono.Cecil.Cil.CodeReader.PatchRawMethodBody(MethodDefinition method, CodeWriter writer, Int32& code_size, MetadataToken& local_var_token)
    at Mono.Cecil.Cil.CodeWriter.WriteUnresolvedMethodBody(MethodDefinition method)
    at Mono.Cecil.Cil.CodeWriter.WriteMethodBody(MethodDefinition method)
    at Mono.Cecil.MetadataBuilder.AddMethod(MethodDefinition method)
    at Mono.Cecil.MetadataBuilder.AddMethods(TypeDefinition type)
    at Mono.Cecil.MetadataBuilder.AddType(TypeDefinition type)
    at Mono.Cecil.MetadataBuilder.AddTypes()
    at Mono.Cecil.MetadataBuilder.BuildTypes()
    at Mono.Cecil.MetadataBuilder.BuildModule()
    at Mono.Cecil.MetadataBuilder.BuildMetadata()
    at Mono.Cecil.ModuleWriter.<>c.<BuildMetadata>b__2_0(MetadataBuilder builder, MetadataReader _)
    at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func`3 read)
    at Mono.Cecil.ModuleWriter.BuildMetadata(ModuleDefinition module, MetadataBuilder metadata)
    at Mono.Cecil.ModuleWriter.Write(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
    at Mono.Cecil.ModuleWriter.WriteModule(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
    at Mono.Cecil.ModuleDefinition.Write(Stream stream, WriterParameters parameters)
    at Unity.Jobs.CodeGen.JobsILPostProcessor.Process(ICompiledAssembly compiledAssembly)
    at Unity.ILPP.Runner.PostProcessingPipeline.PostProcessAssemblyAsync(PostProcessAssemblyRequest request, Action`2 progressSink)
    PostProcessing failed
    Unhandled Exception: System.InvalidOperationException: Post processing failed
    at Unity.ILPP.Trigger.TriggerApp.<ProcessArgumentsAsync>d__1.MoveNext() + 0xa2d
    --- End of stack trace from previous location ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x20
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xb6
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x42
    at Unity.ILPP.Trigger.TriggerApp.<RunAsync>d__0.MoveNext() + 0xdc
    --- End of stack trace from previous location ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x20
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xb6
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x42
    at Program.<<Main>$>d__0.MoveNext() + 0x153
    --- End of stack trace from previous location ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x20
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xb6
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x42
    at Program.<Main>(String[]) + 0x20
    at Unity.ILPP.Trigger!<BaseAddress>+0x58bc7f

    Did you find the solution?
     
  3. Mockarutan

    Mockarutan

    Joined:
    May 22, 2011
    Posts:
    159
    No, I've removed all but the code that goes into Assembly-CSharp.dll, and as soon as I put that in, I get the error back. I've thought about trying to add parts of it at a time and see where is breaks, but it's quite a bit of code with pretty scattered dependencies so it's maybe too time consuming to do. Right now I'm just waiting for the next release, or until I get some smart ideas to try.
     
  4. TurboDrew17

    TurboDrew17

    Joined:
    Jul 16, 2013
    Posts:
    1
    I too started running into this, but I am very new at Entities/Jobs so figured I was missing something. Below is sample code I have that was simplified for this purpose and see if it gives you any ideas. I was getting started by following this tutorial for moving tanks: https://github.com/Unity-Technologi...blob/master/DOTS_Guide/ecs_tutorial/README.md

    I tried to use this logic with the idea of having multiple enemies moving around. I know passing in speed the way below is not the intended way to keep data, but this is to show what exactly causes the issue. If I want to pre-calculate some variable and then use that on each of the entity data, this is the way we should do it right?

    Passing in the "dt" works fine and compiles as it should. But if I try to pass in a variable that I define, it won't work. I even tried making structs with ReadOnly attributes like the DeltaTime is, but with no luck. The comments in the tuturial are included below and mention making a local variable for the DeltaTime, so how does speed not then work for the local variable?

    Code (CSharp):
    1. partial class ErrorSystem : SystemBase
    2. {
    3.     protected override void OnUpdate()
    4.     {
    5.         // The Entities.ForEach below is Burst compiled (implicitly).
    6.         // And time is a member of SystemBase, which is a managed type (class).
    7.         // This means that it wouldn't be possible to directly access Time from there.
    8.         // So we need to copy the value we need (DeltaTime) into a local variable.
    9.         var dt = SystemAPI.Time.DeltaTime;
    10.  
    11.         var speed = 5f;
    12.  
    13.         Entities
    14.             .WithAll<Enemy>()
    15.             .ForEach((Entity entity, TransformAspect transform) =>
    16.             {
    17.                 var direction = math.normalize(-transform.Position);
    18.  
    19.                 transform.Position += direction;                // Works
    20.                 transform.Position += direction * dt;           // Works
    21.                 transform.Position += direction * dt * speed;   // Doesn't work
    22.             }).ScheduleParallel();
    23.     }
    24. }
    ** Update ** Now the code won't compile if I remove the problem variables. Even if I remove speed, dt, etc it has an issue with the entire ForEach section. So could be something else entirely
     
    Last edited: Oct 19, 2022
  5. rjohnson06

    rjohnson06

    Joined:
    May 27, 2017
    Posts:
    17
    Had the same error, was able to fix it by removing a ForEach which had a lambda with an empty body.
     
  6. Rob-A

    Rob-A

    Joined:
    Aug 7, 2012
    Posts:
    33
    I had the following code:
    Code (CSharp):
    1. Entities.ForEach((ref TileData td) => {
    2.      td.OnTile = Entity.Null;
    3.      td.Visible = false;
    4. }).WithName("Clear_Unit_Tile_Data").ScheduleParallel();
    I had to change it to:
    Code (CSharp):
    1. var eNull = Entity.Null; //NOTE: this is to prevent a Burst bug
    2. Entities.ForEach((ref TileData td) => {
    3.      td.OnTile = eNull;
    4.      td.Visible = false;
    5. }).WithName("Clear_Unit_Tile_Data").ScheduleParallel();
    This was working in entities 0.17 with corresponding packages and appeared when switching to entities 1.0.0-pre.15
     
    Last edited: Jan 20, 2023
  7. slims

    slims

    Joined:
    Dec 31, 2013
    Posts:
    86
    How did you track this down? I have a bazillion systems using Entities.ForEach, it would be hard to guess what the real problem is.
     
    Mockarutan and MuntyMcFly like this.
  8. Mockarutan

    Mockarutan

    Joined:
    May 22, 2011
    Posts:
    159
    I Actually went though my whole source and changed to that in all cases where I used Entity.Null in a Entities.ForEach. But it dit not help... Too bad
     
  9. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Did anyone figured out the cause?
    Having same issue with Unity 2022.3.5f1 + Entities 1.0.11;
     
  10. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Okay, just after a couple of tests it seems that:
    - Entities.ForEach with ScheduleParallel + SystemBase
    -- or --
    - Job.WithCode + SystemBase
    is no longer supported.

    With both cases replaced with IJobEntity & IJob respectively, compilation works again.
    Proper error message would be great though.
     
  11. diesoftgames

    diesoftgames

    Joined:
    Nov 27, 2018
    Posts:
    122
    I'm getting a very similar error, but only when I try to build the Addressables content. It's slightly different though, it says more specifically:
    Unity.Jobs.CodeGen.JobsILPostProcessor: ILPostProcessor has thrown an exception: System.ArgumentNullException: Value cannot be null. (Parameter 'fieldType')
     
  12. diesoftgames

    diesoftgames

    Joined:
    Nov 27, 2018
    Posts:
    122
    I've tracked my particular version of this error down to a pretty weird place after slowly commenting out all my systems one-by-one: it was a call to
    UnityEngine.Debug.LogWarning
    inside a SystemBase's OnUpdate method. The call was nested within two lambdas, but did NOT use any Job related stuff (at least it wasn't attempting to, no calls to Entities in there).
     
  13. gabrieloc

    gabrieloc

    Joined:
    Apr 6, 2014
    Posts:
    49
    Following the advice of members of this thread, I went through the process of deleting and restoring every system in my codebase and tracked the issue down to a specific job in a specific system.

    The job writes to a collection of type
    NativeParallelMultiHashMap
    which has a tuple value type. The tuple was expressed as a literal, and writing out
    ValueTuple
    made no difference.

    I replaced the tuple with a struct and the error appears to be gone.

    This one was particularly fun because I use tuples quite a bit in my codebase and I have no clue how I'd debug this beautifully cryptic error otherwise.

    EDIT: Turns out this class is pretty picky, in another area I had a hashmap property with a value type of
    FixedList
    . Must be other hidden constraints out there yet...
     
    Last edited: Oct 21, 2023
  14. Rafal_Marchewka

    Rafal_Marchewka

    Joined:
    Apr 1, 2021
    Posts:
    5
    I'm upgrading big project from Unity 2019 + Entities 0.11 to Unity 2022 + Entities 1.0.16 and I have same error.
    And I've found, that if You have two identical Lambdas in different Systems, this error occures. We have few dozens of "simple checks" with different structures in WithAll() and I had to make static, generic method and use it instead of old ones. Weird but ok.

    BUT
    We have 2 different ForEach-es: one is creating 2 new Entites, based on "if Entity have this Component", then it add another component to Entity. Other one is adding one new Entity, based on data in component, gained by ForEach( [...] in Component c) and adding new component to entity, just as previous one.
    If one of them is commented and other one is functional: everything is fine. If both are NOT commented: error is occuring.

    Workaround: rewriting it to SystemAPI.Query don't cause this error but I even don't know if it's working... I have about 300 querries to rewrite...

    We really regret that we used Unity Entities in our project... It's complete mess, next impossible to debug, when you have 100 systems, with 2-5 Entities.ForEach in every of them and all You can see is "System.ArgumentNullException". For f. sake, we have 2023, not 1980, proper Error Message should be obvious in such cases!

    Update: Workaround works only partialy, because You can't make structural changes with SystemAPI.Query foreach...

    Update 2: It's working! How I've fixed it? I have no slightest idea! It's just started working by it's own. My guess is that I've changed something in Burst settings and then, restarted Unity
    Update 2.5: Works in editor, same error during build...

    Update 3: FINALLY FIXED
    There is limit of ForEach.WithoutBurst. I don't know if this limit is to single Assembly or project, but I reduced number of them to 256 and it's starts working somehow. I had to rewrite half of ForEaches WITHOUT structural changes to SystemAPI.Query.
    I don't know if it's limit per project, per Assembly or what. You can declare max 256 "WithoutBurst" ForEaches. It isn't mentioned in documentation or anything...
     
    Last edited: Nov 21, 2023
  15. IliqNikushev

    IliqNikushev

    Joined:
    Feb 1, 2017
    Posts:
    22
    Had the same issue, twice

    first time fix: Just made a new assembly and put the code that has too many defines/references in there

    Seems like the code-generator breaks without a proper error message (Entities 1.0.10) (Unity 2022.3.14)

    121 defines and 223 references

    not using WithoutBurst

    Currently migrating from 0.5, this did not happen then

    Second time i it happened with this pseudo code:
    Code (CSharp):
    1.  
    2. This does not work
    3. Entities.ForEach((DynamicBuffer<Response> responses, ref PlayerUpgrades component) =>
    4. {
    5.     if (responses.Length == 0)
    6.         return;
    7.     component = responses[0].response;
    8.     responses.Clear();
    9. }).Run();
    10.  
    11. made it work by having:
    12. int i = 0; // <----
    13. Entities.ForEach((DynamicBuffer<Response> responses, ref PlayerUpgrades component) =>
    14. {
    15.     i += 1; // <<<---- making a local variable allows the code-generator to make the function in the background
    16.     if (responses.Length == 0)
    17.         return;
    18.     component = responses[0].response;
    19.     responses.Clear();
    20. }).Run();
    21.  
    22. where
    23. public struct PlayerUpgrades : IComponentData
    24. {
    25.     public int level;
    26. }
    Creating a new assembly did not help, because the current code (where this is failing) has 12 for-eaches total xD
     
  16. TrueJollyRoger

    TrueJollyRoger

    Joined:
    Dec 23, 2017
    Posts:
    9
    Have the same bug. However, my colleague doesn't have this bug with the same branch.
     
  17. msfredb7

    msfredb7

    Joined:
    Nov 1, 2012
    Posts:
    163
    (Entities 1.0.16, 1.1.0-pre.3, 1.2.0-pre.6) I simplified my code over and over to try to pinpoint the issue. In this code, it seems the only way to remove the error is to remove the Entities.ForEach altogether...
    Code (CSharp):
    1. public partial class WtfSystem : SimSystemBase
    2. {
    3.     protected override void OnUpdate()
    4.     {
    5.         Entities.ForEach((Entity entity) =>
    6.         {
    7.             Debug.Log("Test");
    8.         }).Run();
    9.     }
    10. }
    11.  
    Not sure what to do...
    EDIT: I tried updating to Entities 1.1.0-pre.3 AND 1.2.0-pre.6 and the issue persists (according to this, I expected the issue to be fixed)
     
    Last edited: Feb 20, 2024
  18. IliqNikushev

    IliqNikushev

    Joined:
    Feb 1, 2017
    Posts:
    22
    Yes, the issue is regarding on how the Entities.ForEach job compiled on the `partial class` deriving from Base Systems

    @msfredb7 can you try this:
    Code (CSharp):
    1.      
    2. var localVariable = 0;
    3.         Entities.ForEach((Entity entity) =>
    4.         {
    5.             Debug.Log("Test");
    6.             localVariable += 1;
    7.         }).Run();
    8.  
    The way it worked for me is to ensure that the 'troublesome' Entities.ForEach queries have a local scoped variable, forcing them to be compiled

    Sadly there is a bug in the way the Entities Framework reworks these functions :/
    All the bugs that i have faced with the transition of entities 0.5 - 1.0 are really just some small edge-cases that probably didn't come out during testing

    As @TrueJollyRoger mentioned, it breaks on a separate computer -> That makes it even more complicated but had the same experience. There is just something that is overlooked, and hopefully the Unity Team notices this thread soon :)

    I Currently have around 500 Entitie.ForEach calls and all of them are working perfectly fine
     
    Last edited: Feb 24, 2024