[英]Checking Mono.Cecil and Mono.Cecil.Cil
我有一些代碼來加載exe文件並向用戶顯示其CIL代碼。 要做到這一點,我使用Mono.Cecil和Mono.Cecil.Cil。
現在我想做一些不同的事情:我想知道用戶是否在他的系統中有Mono.Cecil和Mono.Cecil.Cil。 要做到這一點,我想使用Reflection.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.Cil。 我沒有正確使用Assembly.Load? 如果是這種情況,有人可以告訴我如何使用Assembly.Load能夠加載Mono.Cecil和Mono.Cecil.Cil而無需查找路徑(在Windows或GNU / Linux下使用一個唯一的exe文件)單聲道)?
注意 :我在Linux Mint下使用MonoDevelop 2.6或在Windows 7下使用MonoDevelop 2.8。
您似乎誤解了Assembly.Load加載程序集的功能。 我想你想要尋找的是用戶是否在GAC中使用Mono.Cecil。 問題是當您提供部分名稱時,僅搜索當前AppDomain的搜索路徑,僅在您提供全名時使用GAC。 這在此處記錄 :
不建議為assemblyRef提供部分程序集名稱。 (部分名稱省略了一個或多個culture,version或public key token。對於采用字符串而不是AssemblyName對象的重載,“MyAssembly,Version = 1.0.0.0”是部分名稱和“MyAssembly”的示例, Version = 1.0.0.0,Culture = neutral,PublicKeyToken = 18ab3442da84b47“是全名的示例。”使用部分名稱會對性能產生負面影響。 此外,只有在應用程序基目錄(BaseDirectory或AppDomainSetup.ApplicationBase)中存在程序集的精確副本時,部分程序集名稱才能從全局程序集緩存加載程序集。
有關CLR探針如何在大會上找到的更多信息,請訪問: http : //msdn.microsoft.com/en-us/library/aa720133.aspx
這正是Assembly.LoadWithPartialName()存在的原因,但它已被棄用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.