2016-04-24 13 views
2

Assembly.Load()関数でのメモリからのEXEファイルが重複していますが、この関数にバイト配列を渡すと、BadImageFomatExceptionアセンブリ名の重複型が発生します。Assembly.Load()名前が '

enter image description here

私のコードは次のとおりです。

try{ 
        // prepare the Form to show balloontip 
        frmDefault frm = new frmDefault(); 

        // prepare to load the application into memory (using Assembly.Load) 

        // read the bytes from the application exe file 
        FileStream fs = new FileStream(filePath, FileMode.Open); 
        BinaryReader br = new BinaryReader(fs); 
        byte[] bin = br.ReadBytes(Convert.ToInt32(fs.Length)); 
        fs.Close(); 
        br.Close(); 

        // load the bytes into Assembly 
        Assembly a = Assembly.Load(bin); 
        // search for the Entry Point 
        MethodInfo method = a.EntryPoint; 
        if (method != null) 
        { 

         // create an istance of the Startup form Main method 
         object o = a.CreateInstance(method.Name); 
         Console.Write("Application started!"); 
         method.Invoke(o, null); 

        } 
        else 
        { 
         // impossible to launch the application 
         Console.Write("Application error!"); 
        } 
       } 
       catch 
       { 

       } 
+0

おそらく、コードの後に​​コードの代わりにコードをポストすることは、もっと役に立つでしょう。また、このコードはどこにありますか?それは複数回呼び出すことができますか?すでに参照されている、またはロードされているアセンブリと同じですか? – Kateract

+1

あなたはそのアセンブリをどこから手に入れましたか?問題のタイプの名前で判断すると、それは難読化されていますか? –

+0

それは複数回呼び出すことはできません。 – user3001228

答えて

0

まず:

var a = Assembly.LoadFile(filePath); 

// read the bytes from the application exe file 
FileStream fs = new FileStream(filePath, FileMode.Open); 
BinaryReader br = new BinaryReader(fs); 
byte[] bin = br.ReadBytes(Convert.ToInt32(fs.Length)); 
fs.Close(); 
br.Close(); 

// load the bytes into Assembly 
Assembly a = Assembly.Load(bin); 

を置き換えることができます

この問題については、同じバイナリファイルから2つの異なるバージョンをロードしているようです。ファイルをロードする場所からダブルを選択します。

+0

ok私のexeファイルをチェックしましたが、2つのアセンブリ情報がありましたが、今は "Bad IL Format"というアイデアはありますか? – user3001228

+0

'LoadFile'はディスク上のアセンブリをロックしますが、同じではありません。 – leppie

+0

Assembly.LoadFileを使用できません。バイト配列 – user3001228