我有一些加载EXE文件的代码,并将其CIL代码显示给用户。要做我用mono.cecil和mono.ceCil.cil。

现在我想做一些不同的东西:我想知道用户是否有mono.cecil和mono.cecil.cin在他的系统中。要做到,我想用反射.Assembly.load与mono.cecil和mono.ceCil.cil。类似:

public void PrintInstr( ) {
    try
    {
        Reflect.Assembly mc = Reflect.Assembly.Load( "Mono.Cecil" );
        Reflect.Assembly mcc = Reflect.Assembly.Load( "Mono.Cecil.Cil" );
    }
    catch( Exception )
    {
        System.Console.WriteLine( "\"Mono.Cecil\" or \"Mono.Cecil.Cil\" not found " );
        return;
    }
    //[...]
}
.

但我只会收到以下错误:

Could not load file or assembly 'Mono.Cecil' or one of its dependencies.
The system cannot find the file specified.
.

当然,我有mono.cecil和mono.cecil.con。我不是使用正确的装配.Load吗?如果是这样的话,有人可以告诉我如何使用汇编程序来加载mono.cecil和mono.cecil.con而无需查找路径(要在Windows或GNU / Linux下使用唯一的exe文件用单声道)?

注意:我在Linux薄荷用Monodevelop 2.6或Windows 7下工作,Monodevelop 2.8。

有帮助吗?

解决方案

你似乎误解了什么 somponent.load < / a>要加载组件。我想你想要寻找什么是用户是否在GAC中有Mono.ceCil。问题是只有在提供部分名称时只搜索当前AppDomain的搜索路径,只有在提供全名时才使用GAC。这被记录在于这里

不建议为AssembLyref提供部分装配名称。 (部分名称省略文化,版本或公钥中的一个或多个 令牌。对于拍摄字符串而不是汇编名称的过载 对象,“myAssembly,Version= 1.0.0.0”是部分名称的示例 和“myAssembly,版本= 1.0.0.0,文化=中立, publicekeytoken= 18ab3442da84b47“是全名的示例。)使用 部分名称对性能产生负面影响。另外,一个 部分汇编名称可以从全局组装加载组件 仅当程序集中的精确副本时才缓存 应用基本目录(依赖性或 AppDomainsetup.ApplicationBase)。

有关如何在此处找到组件的CLR探针的更多信息: http: //msdn.microsoft.com/en-us/library/aa720133.aspx

这正是 somponent.loadwithpartialname()存在,但它已被弃用。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top