My scenario – I am trying to send a Assembly File from Server to Client (via direct TCP connection). But the major problem is- how do I convert this Assembly to bytes to that it can be readily transferred? I used 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 –
Could not load file or assembly ‘165 bytes loaded from Code generator server, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. An attempt was made to load a program with an incorrect format. Please help!!!
Wouldn’t that just be the raw dll contents, as though you had saved it to disk? i.e. the equivalent of
File.ReadAllBytes?It sounds like the dll is generated – can you save it anywhere? (temp area, memory stream, etc)?
edit Since it seems you are using code-dom, try using
PathToAssembly(on the compiler-results) andFile.ReadAllBytes(or a similar streaming mechanism).