2017-06-13 52 views
1

出於某種原因,當我嘗試加載一些組裝和分析它,我收到提示Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly...單塞西爾添加缺少的組件

我真的不關心爲什麼這個異常拋出,我知道哪裏是失蹤部件。

有一種方法來一些類似AppDomain.CurrentDomain.AssemblyResolve事件,但對於Mono.Cecil能做到? 我可以手動加載缺少的組件,但我不知道怎麼辦。
所以,我怎樣才能加載Mono.Cecil能組裝?

回答

1

顯然Mono.Cecil能支持。 當您與AssemblyDefinition.ReadAssembly加載組件內部的ReadParameters你可以改變AssemblyResolver屬性爲您解析。

要創建一個解析器從BaseAssemblyResolver像是剛剛繼承:

private class CustomResolver : BaseAssemblyResolver 
{ 
    private DefaultAssemblyResolver _defaultResolver; 

    public Resolver(string sourceDir) 
    { 
     _defaultResolver = new DefaultAssemblyResolver(); 
    } 

    public override AssemblyDefinition Resolve(AssemblyNameReference name) 
    { 
     AssemblyDefinition assembly; 
     try 
     { 
      assembly = _defaultResolver.Resolve(name); 
     } 
     catch (AssemblyResolutionException ex) 
     { 
      assembly = ...; // Your resolve logic 
     } 
     return assembly; 
    } 
}