2012-03-13 15 views
1

私はexeファイルを読み込むコードをいくつか持っており、そのCILコードをユーザーに示しています。これを行うには、私はMono.CecilとMono.Cecil.Cilを使用します。Mono.CecilとMono.Cecil.Cilを確認する

今私は別の何かをしたいと思っています。ユーザーがMono.CecilとMono.Cecil.Cilを自分のシステムに持っているかどうかを知りたいのですが。これを行うには、Mono.CecilとMono.Cecil.CilでReflection.Assembly.Loadを使用すると考えました。ような何か:

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ファイルを使用するようにしますモノと一緒に)?

ノート:私はMonoDevelop 2.6でLinux Mint、MonoDevelop 2.8でWindows 7で作業しています。

+0

Cecilがグローバルアセンブリキャッシュに含まれているかどうか確認したいのですか? – svick

答えて

3

アセンブリをロードするのに、Assembly.Loadは何を誤解しているようです。あなたが探しているものは、ユーザーがGACにMono.Cecilを持っているかどうかです。問題は、一部の名前を指定したときに現在のAppDomainの検索パスのみが検索され、フルネームを指定した場合にのみGACが使用されることです。 Assembly.LoadWithPartialName()が存在する理由http://msdn.microsoft.com/en-us/library/aa720133.aspx

これは正確であるが、それは廃止されました:アセンブリのためのCLRプローブはここで見つけることができますどのように

Supplying a partial assembly name for assemblyRef is not recommended. (A partial name omits one or more of culture, version, or public key token. For overloads that take a string instead of an AssemblyName object, "MyAssembly, Version=1.0.0.0" is an example of a partial name and "MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=18ab3442da84b47" is an example of a full name.) Using partial names has a negative effect on performance. In addition, a partial assembly name can load an assembly from the global assembly cache only if there is an exact copy of the assembly in the application base directory (BaseDirectory or AppDomainSetup.ApplicationBase).

詳細情報:これはhereに記載されています。

関連する問題