TypeLoadException - Could not load type because the format is invalid

  • Thread starter Thread starter O.B.
  • Start date Start date
O

O.B.

I recently changed a struct to a class and made its layout Sequential
instead of Explicit for Marshalling. And now I'm getting the
following error when running my unit tests. I have verified that all
DLLs and EXEs are being completely rebuilt. Is there a way to find
out what "format" is invalid or what format is expected?

System.TypeLoadException: Could not load type
'MUSE.DIS.PDUs.Entity.EntityState' from assembly 'MUSE_Common,
Version=8.1.0.21285, Culture=neutral, PublicKeyToken=null' because the
format is invalid.
 
Here's some more information. If I remove the StructLayout
declaration from the following code. It runs but then bombs when it
comes to doing the Marshaling.

namespace MUSE.DIS.PDUs.Entity
{
[StructLayout(LayoutKind.Sequential, Pack=1)]
public class EntityState : PDU
{
// Hidden
}
}

As used in test code:

EntityState testPDU = new EntityState();
 
You will need to post the structure definition, the original signature
of the function (in C++), the function as declared in C# as well as how it
is called. Without those, it's very difficult to tell what is going on.
 
The problem has been resolved. EntityState inherited from PDU and PDU
did not have a StructLayout declared. I would have never guessed that
from the TypeLoadException message. Maybe Microsoft could beef the
message up somewhat?



    You will need to post the structure definition, the original signature
of the function (in C++), the function as declared in C# as well as how it
is called.  Without those, it's very difficult to tell what is going on..

--
          - Nicholas Paldino [.NET/C# MVP]
          - (e-mail address removed)


Here's some more information.  If I remove the StructLayout
declaration from the following code.  It runs but then bombs when it
comes to doing the Marshaling.
namespace MUSE.DIS.PDUs.Entity
{
 [StructLayout(LayoutKind.Sequential, Pack=1)]
 public class EntityState : PDU
 {
   // Hidden
 }
}
As used in test code:
EntityState testPDU = new EntityState();
 
Back
Top