Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. c# 64 bit .net c++ dll reference problem

c# 64 bit .net c++ dll reference problem

Scheduled Pinned Locked Moved C#
csharphelpc++tutorialannouncement
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    peter462
    wrote on last edited by
    #1

    I wrote one .net c++ dll,and reference it in an c# winform program .Prompt the following error: title: BadImageFormatException was unhandled content: Could not load file or assembly “CppDll, Version=1.0.4798.31848, Culture=neutral, PublicKeyToken=null”or one of its dependencies. the Default cpu settings is anycpu,when i change it to x64,the result is the same.but when i change it to x86 it can work well. This is a very simple test example code: part dll code:

    namespace CppDll {

    public ref class Class1
    {
        // TODO: Add your methods for this class here.
    };
    

    }

    part exe code:

    public Form1()
    {
    CppDll.Class1 cls = new CppDll.Class1();
    InitializeComponent();
    }

    N D L 3 Replies Last reply
    0
    • P peter462

      I wrote one .net c++ dll,and reference it in an c# winform program .Prompt the following error: title: BadImageFormatException was unhandled content: Could not load file or assembly “CppDll, Version=1.0.4798.31848, Culture=neutral, PublicKeyToken=null”or one of its dependencies. the Default cpu settings is anycpu,when i change it to x64,the result is the same.but when i change it to x86 it can work well. This is a very simple test example code: part dll code:

      namespace CppDll {

      public ref class Class1
      {
          // TODO: Add your methods for this class here.
      };
      

      }

      part exe code:

      public Form1()
      {
      CppDll.Class1 cls = new CppDll.Class1();
      InitializeComponent();
      }

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      peter462 wrote:

      the Default cpu settings is anycpu,when i change it to x64,the result is the same.but when i change it to x86 it can work well.

      Where are you changing? In the C# project?

      Best wishes, Navaneeth My blog

      1 Reply Last reply
      0
      • P peter462

        I wrote one .net c++ dll,and reference it in an c# winform program .Prompt the following error: title: BadImageFormatException was unhandled content: Could not load file or assembly “CppDll, Version=1.0.4798.31848, Culture=neutral, PublicKeyToken=null”or one of its dependencies. the Default cpu settings is anycpu,when i change it to x64,the result is the same.but when i change it to x86 it can work well. This is a very simple test example code: part dll code:

        namespace CppDll {

        public ref class Class1
        {
            // TODO: Add your methods for this class here.
        };
        

        }

        part exe code:

        public Form1()
        {
        CppDll.Class1 cls = new CppDll.Class1();
        InitializeComponent();
        }

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        It doesn't work because you compiled your C++ .DLL as 32-bit. You cannot mix 32- and 64-bit code in the same process. Either recompile your .DLL as 64-bit or go into your C# project properties and target x86 (32-bit) to force your C# code to run as 32-bit only.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak

        1 Reply Last reply
        0
        • P peter462

          I wrote one .net c++ dll,and reference it in an c# winform program .Prompt the following error: title: BadImageFormatException was unhandled content: Could not load file or assembly “CppDll, Version=1.0.4798.31848, Culture=neutral, PublicKeyToken=null”or one of its dependencies. the Default cpu settings is anycpu,when i change it to x64,the result is the same.but when i change it to x86 it can work well. This is a very simple test example code: part dll code:

          namespace CppDll {

          public ref class Class1
          {
              // TODO: Add your methods for this class here.
          };
          

          }

          part exe code:

          public Form1()
          {
          CppDll.Class1 cls = new CppDll.Class1();
          InitializeComponent();
          }

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          This is why the default setting isn't Any CPU anymore.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups