TypeLoadException - Could not load type because the format is invalid

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.
 
O

O.B.

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();
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
O

O.B.

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();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top