When building a project under the version .NET 4.x and IL2CPP under Windows this error occurs:
IL2CPP error for method ‘System.Void Unity.Properties.Generated.PropertyBagRegistry::Initialize()’ in assembly ‘D:\KJPIGames\Projects\Lady of Dreams\Temp\StagingArea\Data\Managed\Unity.Rendering.Hybrid.dll’
System.NullReferenceException: Object reference not set to an instance of an object.
at Unity.IL2CPP.Contexts.Components.VTableBuilderComponent.VTableFor(ReadOnlyContext context, TypeReference typeReference)
at Unity.IL2CPP.Contexts.Components.VTableBuilderComponent.VTableFor(ReadOnlyContext context, TypeReference typeReference)
at Unity.IL2CPP.AssemblyConversion.PrimaryCollection.Steps.PerAssembly.AssemblyCollection.CollectGenericMethodsFromVTableSlots(GlobalPrimaryCollectionContext context, AssemblyDefinition item)
at Unity.IL2CPP.AssemblyConversion.PrimaryCollection.Steps.PerAssembly.AssemblyCollection.ProcessItem(GlobalPrimaryCollectionContext context, AssemblyDefinition item)
at Unity.IL2CPP.AssemblyConversion.Steps.Base.ScheduledItemsStepFunc5.WorkerWrapper(WorkItemData3 workerData)
at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler1.ContinueWithResultsWorkItem4.InvokeWorker(Object context, Int32 uniqueId)
at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler1.BaseContinueWorkItem2.Invoke(Object context, Int32 uniqueId)
at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler`1.WorkerLoop(Object data)
I have the same problem. After some modifications of proejct scripts, the IL2CPP build failed, but the stack trace is not relevant to modificaionts, and the error seems random.
We use unity version 2020.3.33f1.
Most of the errors are from CollectGenericMethodsFromVTableSlots, such as:
IL2CPP error for type ‘/__StaticArrayInitTypeSize=960’ in assembly ‘F:\dev\undying\trunk_NS\Temp\StagingArea\Managed\Unity.RenderPipelines.Universal.Runtime.dll’
System.NullReferenceException: Object reference not set to an instance of an object.
at Unity.IL2CPP.Metadata.VTableBuilder.VTableFor(ReadOnlyContext context, TypeReference typeReference)
at Unity.IL2CPP.Metadata.VTableBuilder.VTableFor(ReadOnlyContext context, TypeReference typeReference)
at Unity.IL2CPP.AssemblyConversion.PrimaryCollection.Steps.PerAssembly.AssemblyCollection.CollectGenericMethodsFromVTableSlots(GlobalPrimaryCollectionContext context, AssemblyDefinition item)
at Unity.IL2CPP.AssemblyConversion.PrimaryCollection.Steps.PerAssembly.AssemblyCollection.ProcessItem(GlobalPrimaryCollectionContext context, AssemblyDefinition item)
at Unity.IL2CPP.AssemblyConversion.Steps.Base.ScheduledItemsStepFunc5.WorkerWrapper(WorkItemData3 workerData)
at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler1.ContinueWithResultsWorkItem4.InvokeWorker(Object context, Int32 uniqueId)
at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler1.BaseContinueWorkItem2.Invoke(Object context, Int32 uniqueId)
at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler`1.WorkerLoop(Object data)
Hello, I would like to report a bug, but I can’t reproduce it in a small demo project, and our project is huge so it is not easy to find out the reason to produce this bug. And we need submit the Nintendo Switch version before the end of this year, so we can not expect a new version of Unity that also have a new version of Nintendo SDK matching it. So we need to find the reason to produce this bug just from the error stack trace.
By the way, I also test on windows platform, the error also occur.
Another common stack trace is:
Exception: IL2CPP error for method ‘System.Void Unity.ThrowStub::ThrowNotSupportedException()’ in assembly ‘E:\Jenkins\workspace\Undying_EA_windows\Temp\StagingArea\Data\Managed\System.dll’
System.ArgumentNullException: Value cannot be null. (Parameter ‘key’)
at System.Collections.Generic.Dictionary2.FindEntry(TKey key) at System.Collections.Generic.Dictionary2.TryGetValue(TKey key, TValue& value)
at Unity.IL2CPP.Contexts.Components.WindowsRuntimeProjectionsComponent.ProjectToWindowsRuntime(TypeReference clrType)
at Unity.IL2CPP.Extensions.GetInterfacesImplementedByComCallableWrapper(TypeReference type, ReadOnlyContext context)
at Unity.IL2CPP.Extensions.NeedsComCallableWrapper(TypeReference type, ReadOnlyContext context)
at Unity.IL2CPP.AssemblyConversion.PrimaryCollection.Steps.PerAssembly.CCWMarshalingFunctionCollection.ProcessItem(GlobalPrimaryCollectionContext context, AssemblyDefinition item)
at Unity.IL2CPP.AssemblyConversion.Steps.Base.ScheduledItemsStepAction2.WorkerWrapper(WorkItemData3 workerData)
at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler`1.WorkerLoop(Object data)
So, whould you please give me some hints of what’s in the C# script could produce these two type of IL2cpp error?
Thanks.
Oh, I am reading the “An introduction to IL2CPP internals” articles written by you, it is very good referecne for IL2CPP.
IL2CPP error for type ‘/__StaticArrayInitTypeSize=48’ in assembly ‘F:\dev\undying\trunk_NS\Temp\StagingArea\Managed\Assembly-CSharp-firstpass.dll’
System.NullReferenceException: Object reference not set to an instance of an object.
at Unity.IL2CPP.Metadata.VTableBuilder.VTableFor(ReadOnlyContext context, TypeReference typeReference)
at Unity.IL2CPP.Metadata.VTableBuilder.VTableFor(ReadOnlyContext context, TypeReference typeReference)
at Unity.IL2CPP.AssemblyConversion.PrimaryCollection.Steps.PerAssembly.AssemblyCollection.CollectGenericMethodsFromVTableSlots(GlobalPrimaryCollectionContext context, AssemblyDefinition item)
at Unity.IL2CPP.AssemblyConversion.PrimaryCollection.Steps.PerAssembly.AssemblyCollection.ProcessItem(GlobalPrimaryCollectionContext context, AssemblyDefinition item)
at Unity.IL2CPP.AssemblyConversion.Steps.Base.ScheduledItemsStepFunc5.WorkerWrapper(WorkItemData3 workerData)
at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler1.ContinueWithResultsWorkItem4.InvokeWorker(Object context, Int32 uniqueId)
at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler1.BaseContinueWorkItem2.Invoke(Object context, Int32 uniqueId)
at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler`1.WorkerLoop(Object data)
Based on the stack trace alone, I suspect there is some invalid IL code here. Maybe an assembly A is referencing assembly B and assembly B was changed but assembly A was not recompiled against it. That is usually the cause of VTable problems like this.
Unfortunately the error message does not give us any details about which assemblies are involved here.
Thanks!
Just as you said, we have found the reason, we use a plugin need generate AOT dll, but after code refractor, some types exists in the DLL are no longer exists. After fix the generated AOT dll, these erros are gone!