问题
I have a program that was original compiled in VS2013. Now that I have VS2015 installed, I have been having issues even getting my application to compile. It is written in C++/CLI. It originally targeted the v120_xp toolset. I tried compiling with that targeted toolset (along with all C++ libraries my program utilizes, which are GraphicsMagick and libsquish). It wouldn't even compile if it targeted that toolset. So I tried targeting v140_xp (a few of the users of my program still use Windows XP). That didn't work either.
So I decided to just target the v140 toolset, and .NET framework version 4.5.2 (it originally targeted 4.0).
It compiled successfully.
But now my program won't even start up. I debug it and I get this:
Exception thrown at 0x77751ed2 in PathCreator.exe: 0xC0000005: Access violation reading location 0x23462c5f.
Debug Assertion Failed!
Program: ...Visual Studio 2015\Projects\PathCreator\Debug\PathCreator.exe
File: minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp
Line: 1037
Expression: _CrtIsValidHeapPointer(block)
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
'PathCreator.exe': Loaded 'C:\Windows\syswow64\dwmapi.dll', Cannot find or open the PDB file.
PathCreator.exe has triggered a breakpoint
Exception thrown at 0x53cb6866 in PathCreator.exe: 0xC0000005: Access violation reading location 0x23462c70.
Exception thrown at 0x76d23e28 in PathCreator.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
An unhandled exception of type 'System.TypeInitializationException' occurred in Unknown Module.
Additional information: The type initializer for '<Module>' threw an exception.
An unhandled exception of type 'System.TypeInitializationException' occurred in Unknown Module.
Additional information: The type initializer for '<Module>' threw an exception.
The program '[4156] PathCreator.exe: Managed (v4.0.30319)' has exited with code -1 (0xffffffff).
The program '[4156] PathCreator.exe: Native' has exited with code -1 (0xffffffff).
I have no idea why this is happening. I'm almost ready to just uninstall VS2015 and go back to VS2013.
Any ideas on what is going on? Any help or pointers are greatly appreciated.
回答1:
I managed to get rid of this problem (so far) by changing the entry point to my program. In the project's Properties page, under Linker->Advanced, I cleared the "Entry Point" option (it was "main"). I then changed my main method (originally defined by an earlier version of Visual Studio as "int main(array ^args)") to "int WinMain(void *var1, unsigned long var2, void *var3)".
According to the VS Help, letting the compiler choose the entry point allows it to make sure "...the C run-time library is initialized correctly, and C++ constructors for static objects are executed". Sounds like the problem we've been having.
I'm not sure whether this problem is showing up now because Microsoft doesn't support winforms in managed C++ anymore or it it is to do with their rearchitecture of the CRT (or something completely different). I'm also not sure whether this is THE correct solution but it seems to have worked for the program I'm working on at the moment.
来源:https://stackoverflow.com/questions/32291678/vs2015-migrated-project-compiles-but-wont-run-debug-assertion-failed