Search Unity

The error when I invoke the Assembly.allReferences

Discussion in 'Editor & General Support' started by watsonsong, Apr 2, 2018.

  1. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    I want to get the allReferences on Assembly:
    Code (CSharp):
    1. var allReferences = assembly.allReferences;
    But I met this error report:
    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. UnityEditor.Compilation.Assembly.<get_allReferences>m__0 (UnityEditor.Compilation.Assembly a) (at C:/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/CompilationPipeline.cs:37)
    3. System.Linq.Enumerable+SelectArrayIterator`2[TSource,TResult].MoveNext () (at <839a3cb835c04d14aeb58d83bb7bc4bd>:0)
    4. System.Collections.Generic.EnumerableHelpers.IterativeCopy[T] (System.Collections.Generic.IEnumerable`1[T] source, T[] array, System.Int32 arrayIndex, System.Int32 count) (at <839a3cb835c04d14aeb58d83bb7bc4bd>:0)
    5. System.Collections.Generic.EnumerableHelpers.Copy[T] (System.Collections.Generic.IEnumerable`1[T] source, T[] array, System.Int32 arrayIndex, System.Int32 count) (at <839a3cb835c04d14aeb58d83bb7bc4bd>:0)
    6. System.Linq.Enumerable+Concat2Iterator`1[TSource].ToArray () (at <839a3cb835c04d14aeb58d83bb7bc4bd>:0)
    7. System.Linq.Enumerable.ToArray[TSource] (System.Collections.Generic.IEnumerable`1[T] source) (at <839a3cb835c04d14aeb58d83bb7bc4bd>:0)
    8. UnityEditor.Compilation.Assembly.get_allReferences () (at C:/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/CompilationPipeline.cs:37)
    The Assembly I get from the CompilationPipeline.GetAssemblies.
    And I found the Assembly.assemblyReferences always contains null, is it a bug?
     
    Last edited: Apr 2, 2018
  2. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    I check the source code from UnityCsReference:
    Code (CSharp):
    1.  
    2. internal static Assembly[] GetAssemblies(EditorCompilation editorCompilation, EditorScriptCompilationOptions additionalOptions)
    3. {
    4.     var scriptAssemblies = editorCompilation.GetAllEditorScriptAssemblies(additionalOptions);
    5.     var assemblies = new Assembly[scriptAssemblies.Length];
    6.  
    7.      var scriptAssemblyToAssembly = new Dictionary<ScriptAssembly, Assembly>();
    8.  
    9.     for (int i = 0; i < scriptAssemblies.Length; ++i)
    10.         scriptAssemblyToAssembly.Add(scriptAssemblies[i], assemblies[i]);
    11.  
    I think the 'assemblies' variable is not assign any value, just add to 'scriptAssemblyToAssembly' as null value.
     
  3. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    I believe this is a bug but I don't know where to commit an issue.
     
  4. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    Is there anybody watching this issue?
     
  5. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,136
    If you think you've encountered a bug in Unity then you should submit a bug report with a minimal reproduction project via the bug reporter. You can find more information about bug reporting here: Unity QA - Bug Reporting
     
  6. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555