Build in bytes

My scenario is I am trying to send a build file from the server to the client (via a direct TCP connection). But the main problem is how do I convert this assembly to bytes so that it can be easily ported? I used the following -

byte[] dllAsArray;
using (MemoryStream stream = new MemoryStream())
{
    BinaryFormatter formatter = new BinaryFormatter();
    formatter.Serialize(stream,loCompiled.CompiledAssembly);
    dllAsArray = stream.ToArray();
}

But when I use -

Assembly assembly = Assembly.Load(dllAsArray);

I get an exception -

Failed to load file or assembly "165 bytes downloaded from the code generator server, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null" or one of its dependencies. An attempt was made to download a program with the wrong format. Please, help!!!

+5
source share
2 answers

dll, ? File.ReadAllBytes?

dll - ? ( , ..)?

. , code-dom, PathToAssembly ( ) File.ReadAllBytes ( ).

+6

ReadAllBytes WriteAllBytes. [] .

// Transfer to byte[]
byte[] data = System.IO.File.ReadAllBytes(@"C:\ClassLibaryOne.dll");

// Write to file again
File.WriteAllBytes(@"C:\ClassLibaryOne.dll", data);

edit. AssemblyBuilder DLL, .Save(_), .

AssemblyBuilder a = ...
a.Save("C:\ClassLibaryTwo.dll);
+4

All Articles