0

I have a p2p app for file transfers using TCP. I am trying to send a DLL file and use reflection to read classes from it using Assembly.LoadFile("file directory") and i get the good old BadImageFormatException.

exception stacktrace

When I run the same file generated on this PC it works smoothly, but after i transfer it using the p2p it doesn't work.

I have tested files of bigger and smaller sizes than the file in question, and they transfer properly with no missed bytes.

For making the file i'm using File.WriteAllBytes() with the received bytes from the other peers. The other files I have tested were .txt and .xml formats and they worked well.

naknik
  • 11
  • 2
  • `For making the file i'm using File.WriteAllBytes() with the received bytes from the other peers.` Please show us that code. Have you used WinDiff or the like to compare the two files and confirm whether they are the exact same file? – mjwills Mar 18 '18 at 20:35
  • 1
    it may be a 32/64 bit problem – Eser Mar 18 '18 at 20:38
  • You may missed sending dependencies. If there is any. – Abdullah Dibas Mar 18 '18 at 20:39
  • 1
    personally, I find the idea of a P2P system that transfers *and loads* a dll from the other end **terrifying** - that could very very easily be exploited if you aren't *very very* careful (for example: checking a code-signing thumbprint against an expected public key) – Marc Gravell Mar 18 '18 at 21:03
  • 1
    based on the exception: the thing you're loading isn't an assembly; have you checked independently that you got the file you expected and that the contents were correct? Testing against .txt and .xml means that it could well be that you're using text-based handling, which won't work correctly for binary (however: binary handling will work fine for .txt and .xml) – Marc Gravell Mar 18 '18 at 21:04

0 Answers0