TypeLoadException - Could not load type because the format is invalid

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • O.B.

    TypeLoadException - Could not load type because the format is invalid

    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.TypeLoad Exception: Could not load type
    'MUSE.DIS.PDUs. Entity.EntitySt ate' from assembly 'MUSE_Common,
    Version=8.1.0.2 1285, Culture=neutral , PublicKeyToken= null' because the
    format is invalid.
  • O.B.

    #2
    Re: TypeLoadExcepti on - Could not load type because the format isinvalid

    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.E ntity
    {
    [StructLayout(La youtKind.Sequen tial, Pack=1)]
    public class EntityState : PDU
    {
    // Hidden
    }
    }

    As used in test code:

    EntityState testPDU = new EntityState();

    Comment

    • Nicholas Paldino [.NET/C# MVP]

      #3
      Re: TypeLoadExcepti on - Could not load type because the format is invalid

      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]
      - mvp@spam.guard. caspershouse.co m

      "O.B." <funkjunk@bells outh.netwrote in message
      news:ad6673c6-8f6b-41e0-972b-7c0716fd6c40@i1 8g2000prf.googl egroups.com...
      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.E ntity
      {
      [StructLayout(La youtKind.Sequen tial, Pack=1)]
      public class EntityState : PDU
      {
      // Hidden
      }
      }
      >
      As used in test code:
      >
      EntityState testPDU = new EntityState();

      Comment

      • O.B.

        #4
        Re: TypeLoadExcepti on - Could not load type because the format isinvalid

        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 TypeLoadExcepti on message. Maybe Microsoft could beef the
        message up somewhat?



        On Nov 11, 12:56 pm, "Nicholas Paldino [.NET/C# MVP]"
        <m...@spam.guar d.caspershouse. comwrote:
            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]
                  - m...@spam.guard .caspershouse.c om
        >
        "O.B." <funkj...@bells outh.netwrote in message
        >
        news:ad6673c6-8f6b-41e0-972b-7c0716fd6c40@i1 8g2000prf.googl egroups.com...
        >
        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.E ntity
        {
         [StructLayout(La youtKind.Sequen tial, Pack=1)]
         public class EntityState : PDU
         {
           // Hidden
         }
        }
        >
        As used in test code:
        >
        EntityState testPDU = new EntityState();

        Comment

        Working...