[fix] 修复当dll中存在指向本程序集内的TypeRef时,dnlib的TypeDef.DefinitionAssembly返回null导致 Link/Analyzer.cs运行抛出异常的bug

main
walon 2024-05-17 21:42:30 +08:00
parent 97dae7fed2
commit 60016d7481
1 changed files with 6 additions and 0 deletions

View File

@ -7,6 +7,7 @@ using System.Threading.Tasks;
using dnlib.DotNet; using dnlib.DotNet;
using HybridCLR.Editor.Meta; using HybridCLR.Editor.Meta;
using UnityEditor; using UnityEditor;
using UnityEngine;
using IAssemblyResolver = HybridCLR.Editor.Meta.IAssemblyResolver; using IAssemblyResolver = HybridCLR.Editor.Meta.IAssemblyResolver;
namespace HybridCLR.Editor.Link namespace HybridCLR.Editor.Link
@ -32,6 +33,11 @@ namespace HybridCLR.Editor.Link
var dnAss = assCollector.LoadModule(rootAss, false); var dnAss = assCollector.LoadModule(rootAss, false);
foreach (var type in dnAss.GetTypeRefs()) foreach (var type in dnAss.GetTypeRefs())
{ {
if (type.DefinitionAssembly == null)
{
Debug.LogWarning($"assembly:{dnAss.Name} TypeRef {type.FullName} has no DefinitionAssembly");
continue;
}
if (!rootAssemblyNames.Contains(type.DefinitionAssembly.Name.ToString())) if (!rootAssemblyNames.Contains(type.DefinitionAssembly.Name.ToString()))
{ {
typeRefs.Add(type); typeRefs.Add(type);