BadImageFormatException from mixed-mode multi-file assembly

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?aWduaGVucnk=?=

    BadImageFormatException from mixed-mode multi-file assembly

    I have mixed-mode multi-file assembly of several netmodules and a dll. All
    are generated using c# compiler, vc++ compiler and vc++ linker from command
    prompt. I can browse the content of the assembly from vs.net ide and roeder's
    ..net reflector, but when I run a c# console project that references to the
    dll, it throws BadImageFormatE xception.

    I'm guessing the error probably has to do with compiler/linker option bits
    that are used to built the assembly.

    link /LTCG /CLRIMAGETYPE:IJ W /NOENTRY /DLL
    /ASSEMBLYMODULE: Release/Shared.netmodul e
    /ASSEMBLYMODULE: Release\Native. netmodule
    /ASSEMBLYMODULE: Release\Numeric s.netmodule
    /ASSEMBLYMODULE: Release\C5Colle ctions.netmodul e /OUT:Release\Com monLib.dll
    Release\Common. dll ..\Src\version. res /LIBPATH:"C:\Pro gram Files\Microsoft
    Visual Studio 8\VC\" /LIBPATH:"../Lib/MKL"

    Does anyone have any ideas of what is wrong?

    -- Thanks Henry
  • RFOG

    #2
    Re: BadImageFormatE xception from mixed-mode multi-file assembly

    Commonly those errors occurs when you have different platform compiled
    assemblies.

    For example, you has compiled one assembly for x86 and other for AnyCPU.
    When the AnyCPU calls the x86 gives the error.

    "ignhenry" <ignhenry@nospa m.nospamwrote in message
    news:97C25F72-6836-4C72-8587-AD846C2D2840@mi crosoft.com...
    >I have mixed-mode multi-file assembly of several netmodules and a dll. All
    are generated using c# compiler, vc++ compiler and vc++ linker from
    command
    prompt. I can browse the content of the assembly from vs.net ide and
    roeder's
    .net reflector, but when I run a c# console project that references to the
    dll, it throws BadImageFormatE xception.
    >
    I'm guessing the error probably has to do with compiler/linker option bits
    that are used to built the assembly.
    >
    link /LTCG /CLRIMAGETYPE:IJ W /NOENTRY /DLL
    /ASSEMBLYMODULE: Release/Shared.netmodul e
    /ASSEMBLYMODULE: Release\Native. netmodule
    /ASSEMBLYMODULE: Release\Numeric s.netmodule
    /ASSEMBLYMODULE: Release\C5Colle ctions.netmodul e /OUT:Release\Com monLib.dll
    Release\Common. dll ..\Src\version. res /LIBPATH:"C:\Pro gram Files\Microsoft
    Visual Studio 8\VC\" /LIBPATH:"../Lib/MKL"
    >
    Does anyone have any ideas of what is wrong?
    >
    -- Thanks Henry
    --
    Microsoft Visual C++ MVP
    =============== =========
    Mi blog sobre programación: http://geeks.ms/blogs/rfog
    Momentos Leves: http://momentosleves.blogspot.com/
    Cosas mías: http://rfog.blogsome.com/
    Libros, ciencia ficción y programación
    =============== =============== ==========
    El amor es ciego, pero el matrimonio le devuelve la vista.
    -- Georg Lichtenberg. (1742-1799) Profesor de física y científico alemán.

    Comment

    • Jeffrey Tan[MSFT]

      #3
      RE: BadImageFormatE xception from mixed-mode multi-file assembly

      Hi Henry,

      Since most of linker options are the same as used in the link below, I did
      not see anything wrong with it.

      lications.aspx

      Also, since the "Add Reference" in the VS IDE works and the .Net Reflector
      works, I think the metadata and manifest of the assembly is correct.

      Can you show me the detailed stack trace of this BadImageFormatE xception as
      it throws at runtime? It is helpful if you can provide both the native and
      managed stack traces. To get the native stack, you may have to turn on the
      unmanaged debugging in the VS debugger->Project Property->Debug->Enable
      unmanaged code debugging. Also, you have to setup the Microsoft symbol
      server correct, so that the native addresses are resolved as function names
      correctly.

      Finally, do you have the detailed steps to help me reproduce this problem?
      Once I can reproduce it locally, I can contact the C++/CLI team to
      collaborate on it. Thanks.

      Best regards,
      Jeffrey Tan
      Microsoft Online Community Support

      Delighting our customers is our #1 priority. We welcome your comments and
      suggestions about how we can improve the support we provide to you. Please
      feel free to let my manager know what you think of the level of service
      provided. You can send feedback directly to my manager at:
      msdnmg@microsof t.com.

      =============== =============== =============== =====
      Get notification to my posts through email? Please refer to
      Gain technical skills through documentation and training, earn certifications and connect with the community

      ications.

      Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
      where an initial response from the community or a Microsoft Support
      Engineer within 1 business day is acceptable. Please note that each follow
      up response may take approximately 2 business days as the support
      professional working with you may need further investigation to reach the
      most efficient resolution. The offering is not appropriate for situations
      that require urgent, real-time or phone-based interactions or complex
      project analysis and dump analysis issues. Issues of this nature are best
      handled working with a dedicated Microsoft Support Engineer by contacting
      Microsoft Customer Support Services (CSS) at
      http://msdn.microsoft.com/subscripti...t/default.aspx.
      =============== =============== =============== =====
      This posting is provided "AS IS" with no warranties, and confers no rights.

      Comment

      • =?Utf-8?B?aWduaGVucnk=?=

        #4
        RE: BadImageFormatE xception from mixed-mode multi-file assembly

        Jeffrey,

        I have created a .NET solution containing some projects and also steps to
        reproduce the problem. I'm using my browser to access the newsgroup and I
        don't see anywhere here I can attached a file. Is it possible to send the
        solution to you?

        --Thanks - Henry

        ""Jeffrey Tan[MSFT]"" wrote:
        Hi Henry,
        >
        Since most of linker options are the same as used in the link below, I did
        not see anything wrong with it.

        lications.aspx
        >
        Also, since the "Add Reference" in the VS IDE works and the .Net Reflector
        works, I think the metadata and manifest of the assembly is correct.
        >
        Can you show me the detailed stack trace of this BadImageFormatE xception as
        it throws at runtime? It is helpful if you can provide both the native and
        managed stack traces. To get the native stack, you may have to turn on the
        unmanaged debugging in the VS debugger->Project Property->Debug->Enable
        unmanaged code debugging. Also, you have to setup the Microsoft symbol
        server correct, so that the native addresses are resolved as function names
        correctly.
        >
        Finally, do you have the detailed steps to help me reproduce this problem?
        Once I can reproduce it locally, I can contact the C++/CLI team to
        collaborate on it. Thanks.
        >
        Best regards,
        Jeffrey Tan
        Microsoft Online Community Support
        >
        Delighting our customers is our #1 priority. We welcome your comments and
        suggestions about how we can improve the support we provide to you. Please
        feel free to let my manager know what you think of the level of service
        provided. You can send feedback directly to my manager at:
        msdnmg@microsof t.com.
        >
        =============== =============== =============== =====
        Get notification to my posts through email? Please refer to
        Gain technical skills through documentation and training, earn certifications and connect with the community

        ications.
        >
        Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
        where an initial response from the community or a Microsoft Support
        Engineer within 1 business day is acceptable. Please note that each follow
        up response may take approximately 2 business days as the support
        professional working with you may need further investigation to reach the
        most efficient resolution. The offering is not appropriate for situations
        that require urgent, real-time or phone-based interactions or complex
        project analysis and dump analysis issues. Issues of this nature are best
        handled working with a dedicated Microsoft Support Engineer by contacting
        Microsoft Customer Support Services (CSS) at
        http://msdn.microsoft.com/subscripti...t/default.aspx.
        =============== =============== =============== =====
        This posting is provided "AS IS" with no warranties, and confers no rights.
        >
        >

        Comment

        • Jeffrey Tan[MSFT]

          #5
          RE: BadImageFormatE xception from mixed-mode multi-file assembly

          Hi Henry,

          Thanks for your feedback.

          Yes, only the Outlook Express can attach a sample project to the newsgroup,
          IE can not. Anyway, please feel free to send your project with the detailed
          reproduce steps to me at: jetan@online.mi crosoft.com(remove "online.")

          I prefer reproduce steps because it allows me to try it step by step and
          validate if any step is invalid or may cause the problem.

          Thanks.

          Best regards,
          Jeffrey Tan
          Microsoft Online Community Support
          =============== =============== ===========
          Delighting our customers is our #1 priority. We welcome your comments and
          suggestions about how we can improve the support we provide to you. Please
          feel free to let my manager know what you think of the level of service
          provided. You can send feedback directly to my manager at:
          msdnmg@microsof t.com.

          This posting is provided "AS IS" with no warranties, and confers no rights.

          Comment

          Working...