Turning on CLR support is causing System.IO.FileLoadException

0

I have a big legacy C++/MFC application which is being extended via a C# class library. There's a C++/CLI wrapper for this so the legacy program doesn't need CLR support turned on, but with that it is impossible to debug through the managed code while running the native project.

Turning on CLR support causes a System.IO.FileLoadException to be thrown immediately on running the program. However, with that one setting turned off, the program runs as expected, I just can't step through the DLL code in the Visual Studio debugger.

I know it doesn't have anything to do with a problem in the code. I have this working perfectly in Visual Studio 2017, but I need to get this working in VS 2012 for various reasons.

Edit to add exception text:

An unhandled exception of type 'System.IO.FileLoadException' occurred in 
Unknown Module.

Additional information: Could not load file or assembly '<Project>, 
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Could not find or load a type. (Exception from HRESULT: 0x80131522)
c#
c++
.net
visual-studio-2012
asked on Stack Overflow Oct 25, 2017 by Brandon Fairburn • edited Oct 25, 2017 by Brandon Fairburn

1 Answer

0

Compile the DLL/executable using /GF switch. Go the Project Properties and

C/C++->Code Generation->Enable String Pooling - Set to “Yes”

Copied from MSDN discussion forum

https://social.msdn.microsoft.com/Forums/vstudio/en-US/1c9c687f-4221-4cdd-8497-dd3bba97de6a/systemiofileloadexception-when-starting-an-mfc-application-parially-compiled-with-clr?forum=vcgeneral

answered on Stack Overflow Oct 25, 2017 by Pavan Chandaka

User contributions licensed under CC BY-SA 3.0