出于某种原因,当我尝试加载一些程序集并对其进行分析时,我收到错误Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly...
我真的不在乎为什么会抛出这个异常,我知道丢失的程序集在哪里。
有一种类似于AppDomain.CurrentDomain.AssemblyResolve
事件的方法,但对于Mono.Cecil?
我可以手动加载丢失的组件,但我不知道如何
那么,我如何为Mono.Cecil加载程序集?
答案 0 :(得分:4)
显然Mono.Cecil支持。
当您在AssemblyDefinition.ReadAssembly
内加载ReadParameters
部件时,可以将AssemblyResolver
属性更改为解析器。
创建解析器只需从BaseAssemblyResolver
继承,如:
private class CustomResolver : BaseAssemblyResolver
{
private DefaultAssemblyResolver _defaultResolver;
public CustomResolver()
{
_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;
}
}