简体   繁体   English

Visual Studio C# 应用程序无法使用调试信息构建

[英]Visual Studio C# app won't build with debugging info

My C# WPF App won't load the symbols file using Visual Studio 2017. I've looked online and checked for the common issues, but can't debug my app.我的 C# WPF 应用程序无法使用 Visual Studio 2017 加载符号文件。我在网上查看并检查了常见问题,但无法调试我的应用程序。 This is new behavior.这是新的行为。 It had been working (at least a few months ago) as part of a multi-project solution.作为多项目解决方案的一部分,它一直在工作(至少几个月前)。 I have no idea what has changed.我不知道发生了什么变化。

I have a breakpoint set after Main() and it shows solid red until I attempt to run in Debug configuration.我在 Main() 之后设置了一个断点,它显示为纯红色,直到我尝试在调试配置中运行。 As a breakpoint didn't stop the execution, I explicitly break.由于断点没有停止执行,所以我明确地中断了。

[STAThread]
static int Main(string[] args)
{
    Application.EnableVisualStyles();   // breakpoint on this line
    Application.SetCompatibleTextRenderingDefault(false);

    Debugger.Break();

Now when running, it pops up with "Symbol file not loaded" and it says "Binary was not built with debug information".现在运行时,它会弹出“未加载符号文件”并显示“二进制文件未使用调试信息构建”。

Checking the "Active (Debug)" configuration project properties, in the Build pane, I see在“构建”窗格中检查“活动(调试)”配置项目属性,我看到了

[x] Define DEBUG constant
[x] Define TRACE constant
[ ] Optimize code

and in the Advanced Build Settings dialog并在“高级构建设置”对话框中

Debugging Information: Full

Running Build->Clean and then Build->Rebuild and I see both the app.exe and app.pdb files newly created in bin/Debug/ directory.运行 Build->Clean,然后 Build->Rebuild,我看到在 bin/Debug/ 目录中新创建的 app.exe 和 app.pdb 文件。 When deleting the bin/ and obj/ directories and rebuilding, I still get the same error when attempting to debug the app.删除 bin/ 和 obj/ 目录并重建时,尝试调试应用程序时仍然出现相同的错误。

When I look at the Debug output, along with various loaded Windows DLLs, symbols loaded, I see my application with "Modules was built without symbols."当我查看调试 output 以及各种加载的 Windows DLL 和符号时,我看到我的应用程序带有“模块是在没有符号的情况下构建的”。

From the Debug->Windows->Modules window I see my app with "Optimized: No" and "Symbol Status: Binary was not built with debug information."从 Debug->Windows->Modules window 我看到我的应用程序显示“优化:否”和“符号状态:二进制文件未使用调试信息构建”。 In this same window, I right-clicked my application, selected "Load Symbols" and selected the bin/Debug/app.pdb file.在同一个 window 中,我右键单击我的应用程序,选择“加载符号”并选择 bin/Debug/app.pdb 文件。 It said, "A matching symbol file was not found in this folder".它说,“在此文件夹中找不到匹配的符号文件”。

I'm going mad trying to figure this one out.我要疯了,想弄清楚这一点。 It seems it should be built with debug information, but it isn't.似乎应该使用调试信息构建它,但事实并非如此。 Can anyone point me in the right direction?谁能指出我正确的方向?

I'm going mad trying to figure this one out.我要疯了,想弄清楚这一点。 It seems it should be built with debug information, but it isn't.似乎应该使用调试信息构建它,但事实并非如此。 Can anyone point me in the right direction?谁能指出我正确的方向?

It is quite strange issue.这是一个很奇怪的问题。 I think you could try these suggestions我想你可以试试这些建议

Suggestion建议

1) please check whether Assembly Name(Right-click on project--> Application ) has whitespace, if so, you should delete the whitespace and rebuild again to test it. 1)请检查Assembly Name(右键单击project--> Application )是否有空格,如果有的话,你应该删除空格并重新构建以测试它。

2) enable Define DEBUG constant and Define TRACE constant by right-click on project--> Build . 2)通过右键单击 project--> Build启用定义 DEBUG 常量定义 TRACE 常量

3) enable option Enable Just My Code and Use Managed Compatibility Mode under Tools --> Options --> Debugging --> General 3)工具-->选项-->调试-->常规下启用选项启用我的代码使用托管兼容模式

4) check whether your xxx.csproj file has <DebugType>full</DebugType> node. 4)检查你的xxx.csproj文件是否有<DebugType>full</DebugType>节点。 If not,you could add it in xxx.csproj :如果没有,您可以将其添加到xxx.csproj中:

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
  <DebugType>Full</DebugType>
</PropertyGroup>

5) Close VS Instance, delete .vs hidden folder under the solution folder, bin and obj folder. 5)关闭VS Instance,删除解决方案文件夹下的.vs隐藏文件夹,bin和obj文件夹。 Then restart your project to test again.然后重新启动您的项目以再次测试。

6) If you install several nuget packages, you could run this command under Tools-->Nuget Package Manager-->Nuget Package Console: 6)如果你安装了几个 nuget 包,你可以在 Tools-->Nuget Package Manager-->Nuget Package Console下运行这个命令:

update-package -reinstall

7) disable any third party extensions under Tools-->Extensions and Updates in case some extensions cause this behavior. 7)在工具-->扩展和更新下禁用任何第三方扩展,以防某些扩展导致此行为。 And do not forget to restart VS.并且不要忘记重新启动VS。

8) if your VS has any latest update, please update it. 8)如果您的VS有任何最新更新,请更新它。

In addition ,此外

If the new created wpf VS2017 project can be debugged successfully and your wpf project is an old project from the old VS version, I suggest you could create a new wpf project in VS2017 and then migrate the old into the new one to test whet. If the new created wpf VS2017 project can be debugged successfully and your wpf project is an old project from the old VS version, I suggest you could create a new wpf project in VS2017 and then migrate the old into the new one to test whet.

You can copy the packages.config file from the old project into the new project's root directory and then run update-package -reinstall to reference these packages to your project automatically.您可以将旧项目中的packages.config文件复制到新项目的根目录中,然后运行update-package -reinstall以自动将这些包引用到您的项目中。

Any feedback will be expected.任何反馈都将被期待。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM