【问题标题】:VS2015: Migrated project compiles, but won't run ("Debug Assertion Failed!")VS2015:迁移的项目编译,但不会运行(“调试断言失败!”)
【发布时间】:2015-10-27 10:33:17
【问题描述】:

我有一个最初在 VS2013 中编译的程序。现在我已经安装了 VS2015,我什至在编译我的应用程序时遇到了问题。它是用 C++/CLI 编写的。它最初针对 v120_xp 工具集。我尝试使用该目标工具集进行编译(以及我的程序使用的所有 C++ 库,它们是 GraphicsMagick 和 libsquish)。如果它针对该工具集,它甚至不会编译。所以我尝试以 v140_xp 为目标(我的程序的一些用户仍然使用 Windows XP)。那也没用。

所以我决定只针对 v140 工具集和 .NET 框架版本 4.5.2(它最初针对 4.0)。

编译成功。

但现在我的程序甚至无法启动。我调试它,我得到了这个:

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).

我不知道为什么会这样。我几乎准备好卸载 VS2015 并返回 VS2013。

对正在发生的事情有任何想法吗?非常感谢任何帮助或指示。

【问题讨论】:

  • 你清理并重新编译了整个项目吗?我最近也切换到 2015 并且升级我的项目后没有这样的问题。
  • 第一个异常可能在内部被捕获和处理,从而导致第二个异常。 Expression: _CrtIsValidHeapPointer(block) 表示内存已损坏,可能是由于写入超出缓冲区的末尾或写入超出类的末尾,因为编写器假定该类大于分配的(例如,当它期望派生类并获取基类或不同类的对象)。将异常设置更改为在最初抛出 0xC0000005 错误时停止,以便您可以看到最初的问题。
  • @KompjoeFriek 是的,我清理了整个项目并重新编译。我还重新编译了 GraphicsMagick 和 libsquish 以针对 v140 工具集,它编译得很好。
  • @1201ProgramAlarm 谢谢,我会试试的。如何更改异常设置以在引发 0xC0000005 时停止?我不太擅长调试(虽然我应该是,但这是我必须努力的事情)。
  • 从调试菜单,windows 子菜单,“异常设置”。展开“Win32 异常”部分并选中 0xC0000005 异常旁边的框。

标签: .net c++-cli visual-studio-2015


【解决方案1】:

通过更改程序的入口点,我设法摆脱了这个问题(到目前为止)。在项目的“属性”页面中,在“链接器”->“高级”下,我清除了“入口点”选项(它是“主”)。然后,我将 main 方法(最初由 Visual Studio 的早期版本定义为“int main(array ^args)”)更改为“int WinMain(void *var1, unsigned long var2, void *var3)”。

根据 VS 帮助,让编译器选择入口点可以确保“...正确初始化 C 运行时库,并执行静态对象的 C++ 构造函数”。听起来像我们一直遇到的问题。

我不确定这个问题现在是否出现了,因为 Microsoft 不再支持托管 C++ 中的 winform,或者这与他们对 CRT 的重新架构(或完全不同的东西)有关。我也不确定这是否是正确的解决方案,但它似乎适用于我目前正在开发的程序。

【讨论】:

    猜你喜欢
    • 2014-09-09
    • 2015-11-25
    • 2017-11-04
    • 2015-06-27
    • 1970-01-01
    • 2016-07-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多