Search Unity

Bug IL2CPP error for method 'System.Void Unity.Properties.Generated.PropertyBagRegistry::Initialize()' i

Discussion in 'Windows' started by MrKsi, Sep 6, 2022.

  1. MrKsi

    MrKsi

    Joined:
    Aug 30, 2020
    Posts:
    139
    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.ScheduledItemsStepFunc`5.WorkerWrapper(WorkItemData`3 workerData)
    at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler`1.ContinueWithResultsWorkItem`4.InvokeWorker(Object context, Int32 uniqueId)
    at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler`1.BaseContinueWorkItem`2.Invoke(Object context, Int32 uniqueId)
    at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler`1.WorkerLoop(Object data)
     
  2. MrKsi

    MrKsi

    Joined:
    Aug 30, 2020
    Posts:
    139
    That's how I understand Unity files.Rendering.Hybrid needs to be compiled into a separate library?
     
  3. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,931
  4. MrKsi

    MrKsi

    Joined:
    Aug 30, 2020
    Posts:
    139
    Fixed the problem by switching to Mono with IL2CPP
     
  5. happyfirecn

    happyfirecn

    Joined:
    Dec 28, 2016
    Posts:
    11
    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 '<PrivateImplementationDetails>/__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.ScheduledItemsStepFunc`5.WorkerWrapper(WorkItemData`3 workerData)
    at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler`1.ContinueWithResultsWorkItem`4.InvokeWorker(Object context, Int32 uniqueId)
    at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler`1.BaseContinueWorkItem`2.Invoke(Object context, Int32 uniqueId)
    at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler`1.WorkerLoop(Object data)
     
  6. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,931
    I don't believe that we received a bug report for this issue. If you can, please submit one: https://unity3d.com/unity/qa/bug-reporting
     
  7. happyfirecn

    happyfirecn

    Joined:
    Dec 28, 2016
    Posts:
    11
    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.Dictionary`2.FindEntry(TKey key)
    at System.Collections.Generic.Dictionary`2.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.ScheduledItemsStepAction`2.WorkerWrapper(WorkItemData`3 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.
     
    Last edited: Nov 4, 2022
  8. happyfirecn

    happyfirecn

    Joined:
    Dec 28, 2016
    Posts:
    11
    Add a new stacktrace, very strange:

    IL2CPP error for type '<PrivateImplementationDetails>/__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.ScheduledItemsStepFunc`5.WorkerWrapper(WorkItemData`3 workerData)
    at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler`1.ContinueWithResultsWorkItem`4.InvokeWorker(Object context, Int32 uniqueId)
    at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler`1.BaseContinueWorkItem`2.Invoke(Object context, Int32 uniqueId)
    at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler`1.WorkerLoop(Object data)
     
  9. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,931
    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.
     
  10. happyfirecn

    happyfirecn

    Joined:
    Dec 28, 2016
    Posts:
    11
    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!
     
    JoshPeterson likes this.