2

I'm making a C++/CLI wrapper for a C++ class, but the DLL created by building my C++/CLI project fails to load in C#, Assembly.Load throws a fileNotFound exception with the message "Could not load file or assembly 'CLIExport.dll' or one of its dependencies. The system cannot find the file specified."

The C++/CLI project includes only the wrapper class, the C++ class, and one header file that the C++ class depends on, for which the source and header files has been added to the solution, no references have been added. Do I need to add references to the C++ class in the C++/CLI project? I don't know what the C# app thinks the assembly is missing, and I don't know what I need to add references to, does the C++/CLI project need to have a reference to every .net type it uses like classes in the System namespace?

Thanks.

Bill Walton
  • 811
  • 1
  • 16
  • 31
  • 1
    Are you trying to load an x86 lib into a 64bit project ? – squelos Mar 05 '12 at 14:21
  • I don't believe so, I made the C++/CLI project on the same machine as the C# project I'm testing it in, on a 64 bit PC. Can you create x86 libs on a 64 bit machine? – Bill Walton Mar 05 '12 at 14:34
  • 1
    Use http://www.dependencywalker.com/ and open the wrapper DLL and see if there any dependencies missing. – Alastair Taylor Mar 05 '12 at 14:59
  • using dependency walker I get an error when I try to open the DLL. "Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module. Error: Modules with different CPU types were found. Warning: At least one delay-load dependency module was not found. Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module." It says IESHIMS.dll is missing – Bill Walton Mar 05 '12 at 15:02
  • After locating IESHIMS.dll and loading the dll in dependency walker again I get the following error. "Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module. Error: Modules with different CPU types were found. Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module." – Bill Walton Mar 05 '12 at 15:05
  • I wouldn't worry about IESHIMS.dll I don't think that is the cause of your problems. – Alastair Taylor Mar 05 '12 at 15:39
  • possible duplicate of [Targetting x86 vs AnyCPU when building for 64 bit window OSes](http://stackoverflow.com/questions/2947264/targetting-x86-vs-anycpu-when-building-for-64-bit-window-oses) – Ben Voigt Mar 05 '12 at 16:52
  • Dependency Walker let me know that I needed to have `Ijwhost.dll` right next to my C++/CLI dll otherwise I get this game error from `AssemblyLoadContext.LoadFromAssemblyPath()`. – Keith Hill Jun 15 '23 at 19:12
  • Er "same" error. – Keith Hill Jun 15 '23 at 19:48

1 Answers1

1

I believe the problem is that you are trying to use unmanaged x86 dlls in a 64bit solution.

Try doing : Right click on your solution, then Configuration manager, and set all your projects to x86, then try building again.

Im pretty sure that your build configuration is inconsistent, therefore the error message (I ran into the same problem a few times ...)

You can read up here : What does the Visual Studio "Any CPU" target mean?

And a quick overview of the different targets in VS : http://visualstudiohacks.com/articles/visual-studio-net-platform-target-explained/

Community
  • 1
  • 1
squelos
  • 1,189
  • 6
  • 16
  • I only have one project in my solution, I've just added the C++ source files to this solution, is that incorrect? Should I have added the whole C++ project to the solution? In the confiruration manager there is no x64/x86 option, I can only change build config(debug/release), Platform(win32 is the only option) and a checkbox marked 'build' – Bill Walton Mar 05 '12 at 15:26
  • Can you not create a new Configuration for your project ? – squelos Mar 05 '12 at 15:29
  • @BillWalton Surely you have two projects? The project that contains the C++ Class and the C++/CLI wrapper class and then the C# project that consumes the DLL produced by the other project? – Alastair Taylor Mar 05 '12 at 15:41
  • That's what I dont understand Alastair, how can you do a C# wrapper for a C++ project, with only one C++/CLI project in your solution ? – squelos Mar 05 '12 at 15:42
  • Sorry I had a C# project in a different place to which I'd given the DLL produced by the C++/CLI project, but theyre not in the same solution. – Bill Walton Mar 05 '12 at 15:51
  • I maintain, you probably have a target problem. – squelos Mar 05 '12 at 15:56
  • 1
    @BillWalton If you open the "Visual Studio Command Prompt" - you will find this in the "Visual Studio Tools" folder in the Start Menu folder for Visual Studio. Then navigate to the directory where the wrapper DLL is and type: CorFlags.exe yourWrapperdll.dll and report back what it says – Alastair Taylor Mar 05 '12 at 16:29
  • You were correct it is an x86 DLL, when I create a new configuration however the only option in the active solution platform dialogue is 'win32', no x86 or x64, and if I create a new active solution platform, the only option in the 'copy setting from' dropdown is win32. – Bill Walton Mar 05 '12 at 16:37