Re: Assembly.Load() cause BadImageFormatException

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



> FileStream fs = new FileStream(fileName, FileMode.Open,
>FileAccess.Read);
> Byte[] body = new Byte[(int)fs.Length];
> fs.Read(buffer, 0, buffer.Length);

There's no guarantee that a single call to Read will fill the byte
array. You should check the return value and if necessary keep calling
Read until everything has been read or the end of the stream is
reached.


>My target is to load an assembly and serialize it for future proposes.
>So I can not use LoadFrom() directly.

But does it load correctly if you use Assembly.LoadFrom(fileName) so
you know that the file isn't corrupt or anything?


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
.



Relevant Pages

  • Re: array of array
    ... If you use array_push() to add one element to the array it's better ... E. Dronkert ... Prev by Date: ...
    (comp.lang.php)
  • Re: Reentrant problem with inet_ntoa in the kernel
    ... 2006/11/3, Brooks Davis: ... >>> to store the result. ... And it returns the address of the array to the ... >>> calling it. ...
    (freebsd-net)
  • Re: Insufficient guarantees for null pointers?
    ... guaranteed to point to the subobject at the beginning of the array, ... for a pointer arithmetic to be defined there must be ... Why should conversion to void* change the pointer's limits? ... the Standard didn't explicitly guarantee in general what the result of ...
    (comp.std.c)
  • Re: Base Normal Form
    ... > What's the difference between calling a table a list of tuples, ... In some formal contexts, I think a list is either empty, or consisting ... In contrast, an array is ... > I'm hazy on the distinction between a relation and a relvar. ...
    (comp.databases.theory)
  • Re: Are these the same arguments?
    ... calling program which were not shown are consistent). ... of the array slices that are changed within the subprogram cannot be ... detail in the the actual calling sequence. ... this is legal in f77 (as long as the actual array elements that are ...
    (comp.lang.fortran)