Something went wrong when PostProcessing the assembly, from Entities.Foreach lambda

Hello. I got this unfriendly error:

Something went wrong while Post Processing the assembly (Assembly-CSharp.dll) :
Sequence contains no matching element
  at System.Linq.Enumerable.Single[TSource] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] predicate) [0x00070]

From this:

      var bufferEntity = streamBufferQuery.GetSingletonEntity();
      var bufferFromEntity = GetBufferFromEntity<SpriteUVData>(false);

      inputDeps = Entities.
            WithNone<StreamBuffer>().
            WithChangeFilter<SpriteUVData>().
            WithNativeDisableParallelForRestriction(bufferFromEntity).
            ForEach(
            (int entityInQueryIndex, in DynamicBuffer<SpriteUVData> uv) =>
            {
            }).Schedule(inputDeps);

That’s with the empty lambda. It goes away if I comment out the WithNativeDisableParallelForRestriction.

I’m guessing maybe it’s from trying to pass a BufferFromEntity in WithNativeDisableParallelFor while also using DynamicBuffer as a type in the arguments in the lambda?

For a little more context, these are for two separate entities that have the same type of Dynamic Buffer, I want to copy all the data from all the individual buffers into one big one (without actually making a copy - to avoid the GC allocations).

I’m dumb, I guess I wasn’t paying attention to the “Sequence contains no matching element” part. The error occurred specifically because i had commented out the code that was using the buffer inside the lambda while I was testing. I still feel like that error message could be a bit clearer about what was wrong there, if at all possible.

Hey @Sarkahn_1 . Glad you figured out the issue causing the error. This error message is indeed not great. We will replace it with something that gives a better idea of what the real problem is. Thank you for bringing this up.

i ran into same problem when i try to use generic types in lambda function, will generics be supported ?

I don’t expect us to support generic types used as lambda parameters, or as arguments to .WithAll<> and friends any time soon. A lot of our compiler smarts depends on being able to know which type you are using. You could still share much of the actual iteration code by extracting the lambda method to a static method, and using that from two different Entities.ForEach. If you have particular usecase that is very hard or very inconvenient to achieve without a generic argument, we’d love to learn more about it to better understand the problem.

n

thx for reply, not that hard though for my case.
an off-topic question, how can visual studio/other ide produce same compile error? my frustration mainly came from after i finish my coding, i start to know Enitities doesn’t support generics in jobs (meanwhile it does support generics in non-job code)

It depends on the IDE and its settings how it compiles the code. I’m not sure which IDE’s currently do which thing by default, but if they relay the compilatino request to unity, and show unity’s output then you get the error when you build in the IDE. if they use a builtin msbuild to compile, you only get the c# specific errors (none in this case), and not the dots compiler errors.

But my error message is:

Something went wrong while Post Processing the assembly (Assembly-CSharp.dll) :
Object reference not set to an instance of an object
  at Unity.Entities.CodeGen.TypeDefinitionExtensions.IsComponentSystem (Mono.Cecil.TypeDefinition arg) [0x00001] in C:\Users\linfu\Documents\Code\RTS\Main\RTS\RTS\Library\PackageCache\com.unity.entities@0.3.0-preview.4\Unity.Entities.CodeGen\CecilExtensionMethods.cs:142
  at Unity.Entities.CodeGen.TypeDefinitionExtensions.IsComponentSystem (Mono.Cecil.TypeDefinition arg) [0x000a2] in C:\Users\linfu\Documents\Code\RTS\Main\RTS\RTS\Library\PackageCache\com.unity.entities@0.3.0-preview.4\Unity.Entities.CodeGen\CecilExtensionMethods.cs:156
  at Unity.Entities.CodeGen.TypeDefinitionExtensions.IsComponentSystem (Mono.Cecil.TypeDefinition arg) [0x000a2] in C:\Users\linfu\Documents\Code\RTS\Main\RTS\RTS\Library\PackageCache\com.unity.entities@0.3.0-preview.4\Unity.Entities.CodeGen\CecilExtensionMethods.cs:156
  at System.Linq.Enumerable+WhereEnumerableIterator`1[TSource].ToArray () [0x0001d] in <351e49e2a5bf4fd6beabb458ce2255f3>:0
  at System.Linq.Enumerable.ToArray[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x0001f] in <351e49e2a5bf4fd6beabb458ce2255f3>:0
  at Unity.Entities.CodeGen.LambdaJobsPostProcessor.PostProcessImpl () [0x00001] in C:\Users\linfu\Documents\Code\RTS\Main\RTS\RTS\Library\PackageCache\com.unity.entities@0.3.0-preview.4\Unity.Entities.CodeGen\LambdaJobs\LambdaJobsPostProcessor.cs:177
  at Unity.Entities.CodeGen.EntitiesILPostProcessor.PostProcess (Mono.Cecil.AssemblyDefinition assemblyDefinition, System.Boolean& madeAChange) [0x00009] in C:\Users\linfu\Documents\Code\RTS\Main\RTS\RTS\Library\PackageCache\com.unity.entities@0.3.0-preview.4\Unity.Entities.CodeGen\EntitiesILPostProcessor.cs:209
  at Unity.Entities.CodeGen.EntitiesILPostProcessors.Process (Unity.CompilationPipeline.Common.ILPostProcessing.ICompiledAssembly compiledAssembly) [0x0004b] in C:\Users\linfu\Documents\Code\RTS\Main\RTS\RTS\Library\PackageCache\com.unity.entities@0.3.0-preview.4\Unity.Entities.CodeGen\EntitiesILPostProcessor.cs:44
  at UnityEditor.Scripting.ScriptCompilation.ILPostProcessing.RunILPostProcessors (UnityEditor.Scripting.ScriptCompilation.ScriptAssembly assembly, System.String outputTempPath) [0x0011b] in <3b74787e58694cdda2c241162159b3b7>:0
  at UnityEditor.Scripting.ScriptCompilation.ILPostProcessing.PostProcess (UnityEditor.Scripting.ScriptCompilation.ScriptAssembly assembly, System.Collections.Generic.List`1[T] messages, System.String outputTempPath) [0x00061] in <3b74787e58694cdda2c241162159b3b7>:0

What’s it mean??

This is a bug. Well improve the error message. Are you able to share this project folder with us?

My Project is too large that i can’t share to you.
If I modify Unity.Entities.CodeGen.CecilExtensionMethods.cs:

The log is:


Is it helpful?

I too have run into this bug, my horrible fix is to change line 142 to:

var baseTypeRef = arg?.BaseType;

But I have to keep remaking this change as the package system keeps resetting it

Another “Something went wrong” error. Having this

class FontRef : IComponentData
{
    public TMPro.TMP_FontAsset Font;
}

anywhere in the project using Entities 0.3 causes the build to fail with the following error:

Something went wrong while Post Processing the assembly (Assembly-CSharp.dll) :
 Member 'UnityEngine.TextCore.Glyph' is declared in another module and needs to be imported
  at Mono.Cecil.MetadataBuilder.LookupToken (Mono.Cecil.IMetadataTokenProvider provider) [0x0003c] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.SignatureWriter.MakeTypeDefOrRefCodedRID (Mono.Cecil.TypeReference type) [0x00000] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.SignatureWriter.WriteTypeSignature (Mono.Cecil.TypeReference type) [0x00161] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.SignatureWriter.WriteGenericInstanceSignature (Mono.Cecil.IGenericInstance instance) [0x00021] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.SignatureWriter.WriteTypeSignature (Mono.Cecil.TypeReference type) [0x000cf] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.SignatureWriter.WriteGenericInstanceSignature (Mono.Cecil.IGenericInstance instance) [0x00021] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.MetadataBuilder.GetMethodSpecSignature (Mono.Cecil.MethodSpecification method_spec) [0x00023] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.MetadataBuilder.CreateMethodSpecRow (Mono.Cecil.MethodSpecification method_spec) [0x00012] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.MetadataBuilder.GetMethodSpecToken (Mono.Cecil.MethodSpecification method_spec) [0x00000] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.MetadataBuilder.LookupToken (Mono.Cecil.IMetadataTokenProvider provider) [0x000cb] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.Cil.CodeWriter.WriteOperand (Mono.Cecil.Cil.Instruction instruction) [0x00229] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.Cil.CodeWriter.WriteInstructions () [0x0002c] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.Cil.CodeWriter.WriteResolvedMethodBody (Mono.Cecil.MethodDefinition method) [0x0002e] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.Cil.CodeWriter.WriteMethodBody (Mono.Cecil.MethodDefinition method) [0x0002b] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.MetadataBuilder.AddMethod (Mono.Cecil.MethodDefinition method) [0x00013] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.MetadataBuilder.AddMethods (Mono.Cecil.TypeDefinition type) [0x00013] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.MetadataBuilder.AddType (Mono.Cecil.TypeDefinition type) [0x000a2] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.MetadataBuilder.AddTypes () [0x00018] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.MetadataBuilder.BuildTypes () [0x00014] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.MetadataBuilder.BuildModule () [0x0009f] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.MetadataBuilder.BuildMetadata () [0x00000] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.ModuleWriter+<>c.<BuildMetadata>b__2_0 (Mono.Cecil.MetadataBuilder builder, Mono.Cecil.MetadataReader _) [0x00000] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.ModuleDefinition.Read[TItem,TRet] (TItem item, System.Func`3[T1,T2,TResult] read) [0x00025] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.ModuleWriter.BuildMetadata (Mono.Cecil.ModuleDefinition module, Mono.Cecil.MetadataBuilder metadata) [0x0000f] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.ModuleWriter.Write (Mono.Cecil.ModuleDefinition module, Mono.Disposable`1[T] stream, Mono.Cecil.WriterParameters parameters) [0x000fb] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.ModuleWriter.WriteModule (Mono.Cecil.ModuleDefinition module, Mono.Disposable`1[T] stream, Mono.Cecil.WriterParameters parameters) [0x00002] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.ModuleDefinition.Write (System.IO.Stream stream, Mono.Cecil.WriterParameters parameters) [0x00019] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Mono.Cecil.AssemblyDefinition.Write (System.IO.Stream stream, Mono.Cecil.WriterParameters parameters) [0x00000] in <58b86858c52b4b5fbb6efedd16c9c16a>:0
  at Unity.Entities.CodeGen.EntitiesILPostProcessors.Process (Unity.CompilationPipeline.Common.ILPostProcessing.ICompiledAssembly compiledAssembly) [0x000df] in C:\Projects\Tests\ECSTests\Library\PackageCache\com.unity.entities@0.3.0-preview.4\Unity.Entities.CodeGen\EntitiesILPostProcessor.cs:58
  at UnityEditor.Scripting.ScriptCompilation.ILPostProcessing.RunILPostProcessors (UnityEditor.Scripting.ScriptCompilation.ScriptAssembly assembly, System.String outputTempPath) [0x0011b] in <cdd38c6cb7c446c6ac90945c7521da61>:0
  at UnityEditor.Scripting.ScriptCompilation.ILPostProcessing.PostProcess (UnityEditor.Scripting.ScriptCompilation.ScriptAssembly assembly, System.Collections.Generic.List`1[T] messages, System.String outputTempPath) [0x00061] in <cdd38c6cb7c446c6ac90945c7521da61>:0

(works fine in the editor)

@linfuqing

I had this error as well and had to downgrade the Collections package. I’m using URP in 2019.3.0f3 on mac with .NET4

Something went wrong while Post Processing the assembly (Assembly-CSharp.dll) :
Failed to resolve System.Collections.Generic.Queue`1
  at Unity.Entities.CodeGen.TypeReferenceExtensions.CheckedResolve (Mono.Cecil.TypeReference typeReference) [0x00000] in E:\Unity Projects\tests0\Library\PackageCache\com.unity.entities@0.4.0-preview.10\Unity.Entities.CodeGen\CecilExtensionMethods.cs:13
  at Unity.Entities.CodeGen.BlobAssetSafetyVerifier.<VerifyMethod>g__IsTypeRestrictedToBlobAssetStorage|3_0 (Mono.Cecil.TypeReference tr, Unity.Entities.CodeGen.BlobAssetSafetyVerifier+<>c__DisplayClass3_0& ) [0x000a1] in E:\Unity Projects\tests0\Library\PackageCache\com.unity.entities@0.4.0-preview.10\Unity.Entities.CodeGen\BlobAssetSafety\BlobAssetSafetyVerifier.cs:64
  at Unity.Entities.CodeGen.BlobAssetSafetyVerifier.VerifyMethod (Mono.Cecil.MethodDefinition method, System.Collections.Generic.HashSet`1[T] _nonRestrictedTypes) [0x0004d] in E:\Unity Projects\tests0\Library\PackageCache\com.unity.entities@0.4.0-preview.10\Unity.Entities.CodeGen\BlobAssetSafety\BlobAssetSafetyVerifier.cs:90
  at Unity.Entities.CodeGen.BlobAssetSafetyVerifier.AssertNoBlobAssetLeavesBlobAssetStorage () [0x0004d] in E:\Unity Projects\tests0\Library\PackageCache\com.unity.entities@0.4.0-preview.10\Unity.Entities.CodeGen\BlobAssetSafety\BlobAssetSafetyVerifier.cs:37
  at Unity.Entities.CodeGen.BlobAssetSafetyVerifier.PostProcessImpl () [0x00007] in E:\Unity Projects\tests0\Library\PackageCache\com.unity.entities@0.4.0-preview.10\Unity.Entities.CodeGen\BlobAssetSafety\BlobAssetSafetyVerifier.cs:20
  at Unity.Entities.CodeGen.EntitiesILPostProcessor.PostProcess (Mono.Cecil.AssemblyDefinition assemblyDefinition, System.Boolean& madeAChange) [0x00007] in E:\Unity Projects\tests0\Library\PackageCache\com.unity.entities@0.4.0-preview.10\Unity.Entities.CodeGen\EntitiesILPostProcessor.cs:231

I got this from upgrading collections to preview 6 0.0.4

@Lucas-Meijer I’d like to provide a scenario in which generics can be helpful, as I just got the following message while trying to add generics support:

Unexpected error while post-processing XXXXXXXXX.ECS.Systems.MouseAbsorptionSystem`1:OnUpdate. Please report this error.
Object reference not set to an instance of an object
  at Unity.Entities.CodeGen.TypeReferenceExtensions.TypeImplements (Mono.Cecil.TypeReference typeReference, System.Type interfaceType) [0x00015] in XXXXXXX\Library\PackageCache\com.unity.entities@0.4.0-preview.10\Unity.Entities.CodeGen\CecilExtensionMethods.cs:60
  at Unity.Entities.CodeGen.TypeReferenceExtensions.IsIComponentDataStruct (Mono.Cecil.TypeDefinition typeDefinition) [0x00000] in XXXXXXX\Library\PackageCache\com.unity.entities@0.4.0-preview.10\Unity.Entities.CodeGen\CecilExtensionMethods.cs:31
  at Unity.Entities.CodeGen.InjectAndInitializeEntityQueryField.WithAllTypeArgumentForLambdaParameter (Mono.Cecil.ParameterDefinition p) [0x00029] in XXXXXXX\Library\PackageCache\com.unity.entities@0.4.0-preview.10\Unity.Entities.CodeGen\LambdaJobs\InjectAndInitializeEntityQueryField.cs:288
  at (wrapper delegate-invoke) System.Func`2[Mono.Cecil.ParameterDefinition,System.ValueTuple`2[Mono.Cecil.TypeReference,System.Boolean]].invoke_TResult_T(Mono.Cecil.ParameterDefinition)
  at System.Linq.Enumerable+SelectArrayIterator`2[TSource,TResult].MoveNext () [0x0003a] in <351e49e2a5bf4fd6beabb458ce2255f3>:0
  at System.Linq.Enumerable+WhereEnumerableIterator`1[TSource].MoveNext () [0x0004e] in <351e49e2a5bf4fd6beabb458ce2255f3>:0
  at System.Collections.Generic.LargeArrayBuilder`1[T].AddRange (System.Collections.Generic.IEnumerable`1[T] items) [0x0005e] in <351e49e2a5bf4fd6beabb458ce2255f3>:0
  at System.Collections.Generic.SparseArrayBuilder`1[T].AddRange (System.Collections.Generic.IEnumerable`1[T] items) [0x00000] in <351e49e2a5bf4fd6beabb458ce2255f3>:0
  at System.Collections.Generic.SparseArrayBuilder`1[T].ReserveOrAdd (System.Collections.Generic.IEnumerable`1[T] items) [0x00017] in <351e49e2a5bf4fd6beabb458ce2255f3>:0
  at System.Linq.Enumerable+Concat2Iterator`1[TSource].ToArray () [0x00015] in <351e49e2a5bf4fd6beabb458ce2255f3>:0
  at System.Linq.Enumerable.ToArray[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x0001f] in <351e49e2a5bf4fd6beabb458ce2255f3>:0
  at Unity.Entities.CodeGen.InjectAndInitializeEntityQueryField.AddGetEntityQueryFromMethod (Unity.Entities.CodeGen.LambdaJobDescriptionConstruction descriptionConstruction, Mono.Cecil.ParameterDefinition[] closureParameters, Mono.Cecil.TypeDefinition typeToInjectIn) [0x002cf] in XXXXXXX\Library\PackageCache\com.unity.entities@0.4.0-preview.10\Unity.Entities.CodeGen\LambdaJobs\InjectAndInitializeEntityQueryField.cs:228
  at Unity.Entities.CodeGen.InjectAndInitializeEntityQueryField.InjectAndInitialize (Mono.Cecil.MethodDefinition methodToAnalyze, Unity.Entities.CodeGen.LambdaJobDescriptionConstruction descriptionConstruction, Mono.Collections.Generic.Collection`1[T] closureParameters) [0x00048] in XXXXXXX\Library\PackageCache\com.unity.entities@0.4.0-preview.10\Unity.Entities.CodeGen\LambdaJobs\InjectAndInitializeEntityQueryField.cs:42
  at Unity.Entities.CodeGen.LambdaJobsPostProcessor.Rewrite (Mono.Cecil.MethodDefinition methodContainingLambdaJob, Unity.Entities.CodeGen.LambdaJobDescriptionConstruction lambdaJobDescriptionConstruction, System.Collections.Generic.List`1[T] warnings) [0x002b6] in XXXXXXX\Library\PackageCache\com.unity.entities@0.4.0-preview.10\Unity.Entities.CodeGen\LambdaJobs\LambdaJobsPostProcessor.cs:334
  at Unity.Entities.CodeGen.LambdaJobsPostProcessor.PostProcessImpl () [0x000b0] in XXXXXXX\Library\PackageCache\com.unity.entities@0.4.0-preview.10\Unity.Entities.CodeGen\LambdaJobs\LambdaJobsPostProcessor.cs:196

(this is using entities v0.4 preview 10)

In our game the player can interact with various types of “elements” (fire, earth, water, …). They all use the same base logic, except for being a different type internally.

Each type requires buffers, several components, systems for collision, mouse and world interaction.
Per type this is about 10 systems (which sums up to like 60 systems). The amount of copy and paste would be quite high, especially during the initial prototyping phase where we still flesh out the mechanics.

Consolidating all elements into one component is also not a great solution, as most of the objects don’t have more than 2 or 3, so that’d be just wasted memory.

I would be grateful if you could reconsider adding generics support or give me some hints as to how not using generics could work in our use case.

Confirmed. I have the same sort of problem using TextMeshPro. Have you found any workaround?

I wasn’t really using TMP, just wanted the glyph info. My hack-around was to copy the relevant data into a ScriptableObject via an editor script. (The postprocessor crashed on anything from UnityEngine.TextCore, so you need to define your own data structure all the way down to ints/floats).

If you need the actual font reference I belive as of Entities 0.3 there was no workaround (haven’t checked since).

Thank you. I was also thinking to move everything related to UI outside of ECS components.
I will try that.

Cheers.

@ , I was unfortunately not able to repro the issue with the current Entities package or 0.3. Can you submit the project with a bug or include some Entities.ForEach sample code that triggers the error? Thanks.

Hi there. I decided to gave up utilizing Unity ECS for my projects and techically got no time to be Unity’s QA for free.

All the best.