Extenject icon indicating copy to clipboard operation
Extenject copied to clipboard

ReflectionBaking NullReferenceException

Open joaokucera opened this issue 2 years ago • 1 comments

Describe the bug

NullReferenceException: Object reference not set to an instance of an object
Zenject.ReflectionBaking.ReflectionBakingInternalUtil.TryForceUnityFullCompile () (at Packages/com.gamehouse.yggdrasil.client.zenject/OptionalExtras/ReflectionBaking/Unity/ReflectionBakingInternalUtil.cs:72)
Zenject.ReflectionBaking.ZenjectReflectionBakingSettingsEditor.OnInspectorGUI () (at Packages/com.gamehouse.yggdrasil.client.zenject/OptionalExtras/ReflectionBaking/Unity/ZenjectReflectionBakingSettingsEditor.cs:116)
UnityEditor.UIElements.InspectorElement+<>c__DisplayClass59_0.<CreateIMGUIInspectorFromEditor>b__0 () (at /Users/bokken/buildslave/unity/build/ModuleOverrides/com.unity.ui/Editor/Inspector/InspectorElement.cs:636)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:189)

To Reproduce I have added ZenjectReflectionBakingSettings and pressed the checkbox "Is Enabled In Editor".

Expected behavior No exception and recompile Unity.

Extenject and Unity info (please complete the following information):

  • Zenject version: 9.2.1
  • Unity version: 2021.3.1f1
  • Project's scripting backend [e.g. Mono/IL2CPP]: IL2CPP

Additional context dirtyAllScriptsMethod variables is null in the method below:

public static void TryForceUnityFullCompile()
{
    Type compInterface = typeof(UnityEditor.Editor).Assembly.GetType(
        "UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface");

    if (compInterface != null)
    {
        var dirtyAllScriptsMethod = compInterface.GetMethod(
            "DirtyAllScripts", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

        dirtyAllScriptsMethod.Invoke(null, null);
    }

    UnityEditor.AssetDatabase.Refresh();
}

Also, I have many asmdef files in my project, would it be an issue?

joaokucera avatar Oct 26 '22 14:10 joaokucera

Prior to Unity 2019.3, the UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface.DirtyAllScripts method existed and was used through reflection to force a recompilation. But now there is a public "preferred" way to do it without using reflection which is UnityEditor.Compilation.CompilationPipeline.RequestScriptCompilation.

WhippetsAintDogs avatar Oct 11 '23 13:10 WhippetsAintDogs