【问题标题】:Unable to debug c# dll project with an external app in Visual Studio 2019 Community edition 16.7.2无法在 Visual Studio 2019 社区版 16.7.2 中使用外部应用程序调试 c# dll 项目
【发布时间】:2020-08-31 06:38:28
【问题描述】:

本项目是使用 kriasoft 的 amibroker .NET SDK 用 C# 开发的“amibroker 插件”。

我已经“构建”了我的插件,当我在“控制台项目”中测试它时它工作正常。但是,当我尝试使用外部应用程序 (Amibroker.exe) 调试它时,Visual Studio 突然关闭,并在几秒钟内启动一个空白的 Visual Studio 窗口,其中包含“附加”选项来代替我们通常看到“开始”运行的位置我们的项目。

我单击附加选项并附加到我的 amibroker 应用程序,它成功显示“Debug.Writeline()”消息。但是我的断点都没有被击中。我的代码在任何窗口中都不可见,就像我调试控制台应用程序时通常那样。

在谷歌的研究中,我发现外部应用程序应该由 Visual Studio 自动启动,并且应该在我的断点处停止。这在我的情况下没有发生。我搜索了很多,甚至更新了整个vs2019,但没有任何进展。

如果有人可以帮助我,那就太好了。

注意:“不调试就开始”工作正常。

关于“无法加载文件或程序集'System.Text.Json”的新信息: 无法加载文件或程序集“System.Text.Json,Version=4.0.1.1,Culture=neutral,PublicKeyToken=cc7b13ffcd2ddd51”或其依赖项之一。系统找不到指定的文件。

错误:510 日志:DisplayName = System.Text.Json,版本=4.0.1.1, 文化=中性,PublicKeyToken=cc7b13ffcd2ddd51(完全指定) 日志:Appbase = file:///C:/Program Files (x86)/AmiBroker_New_6.0/ 日志: 初始 PrivatePath = NULL 调用程序集:(未知)。错误:510 日志: 此绑定在默认加载上下文中开始。日志:无申请 找到配置文件。 LOG:使用主机配置文件:LOG: 使用来自的机器配置文件 C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config。 LOG:后策略参考:System.Text.Json,Version=4.0.1.1, 文化=中性,PublicKeyToken=cc7b13ffcd2ddd51 日志:正在尝试 下载新的 URL file:///C:/Program Files (x86)/AmiBroker_New_6.0/System.Text.Json.DLL。日志:尝试下载 新 URL 文件:///C:/Program Files (x86)/AmiBroker_New_6.0/System.Text.Json/System.Text.Json.DLL。日志: 正在尝试下载新的 URL file:///C:/Program Files (x86)/AmiBroker_New_6.0/System.Text.Json.EXE。日志:尝试下载 新 URL 文件:///C:/Program Files (x86)/AmiBroker_New_6.0/System.Text.Json/System.Text.Json.EXE。

我的 packages.config 条目:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="CsvTextFieldParser" version="1.2.1" targetFramework="net461" />
  <package id="Microsoft.Bcl.AsyncInterfaces" version="1.1.0" targetFramework="net461" />
  <package id="System.Buffers" version="4.5.1" targetFramework="net461" />
  <package id="System.Memory" version="4.5.4" targetFramework="net461" />
  <package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net461" />
  <package id="System.Runtime.CompilerServices.Unsafe" version="4.7.1" targetFramework="net461" />
  <package id="System.Text.Encodings.Web" version="4.7.1" targetFramework="net461" />
  <package id="System.Text.Json" version="4.7.1" targetFramework="net461" />
  <package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net461" />
  <package id="System.ValueTuple" version="4.5.0" targetFramework="net461" />
  <package id="UnmanagedExports" version="1.2.7" targetFramework="net461" />
</packages>

app.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <probing privatePath="ghyiouys\;Plugins\;plugins;"/>
            <dependentAssembly>
                <assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
                <codeBase version="4.0.1.1" href="Plugins/System.Text.Json.dll"/>
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
                <codeBase version="4.1.4.0" href="Plugins/System.Numerics.Vectors.dll"/>
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

【问题讨论】:

  • 在c#代码进入dll的地方放一个断点。使用 F11 进入 dll 的步骤。然后加断点,看看代码是否停止。
  • @jdweng 我是 c# 新手,所以我不确定我所做的是否正确。我所做的是: dll 中调用的第一个函数是“GetPluginInfo()”。我在函数大括号处放了一个断点。然后我尝试开始调试。我的外部应用程序仍然没有加载。另一方面,我尝试从调试->新断点->函数断点的第二个窗口(具有附加选项的窗口)添加断点。它奏效了。
  • 另一件让我困惑的事情是,如果我已经在 VS 项目属性的调试选项中提到了外部程序,为什么还要附加一个外部程序。我认为问题从这里开始。
  • 我不知道答案。它可能与从 pdb 文件加载调试数据有关。我怀疑并非所有调试信息都会自动加载以节省内存。一个项目 sln 文件有多个部分,并且只有主要部分被加载。请参阅:docs.microsoft.com/en-us/visualstudio/extensibility/internals/…

标签: c# visual-studio visual-studio-debugging amibroker


【解决方案1】:

无法在 Visual Studio 中使用外部应用程序调试 c# dll 项目 2019社区版16.7.2

如果你只是想通过一个VS在调试过程下只用外部程序进入断点,因为VS无法通过外部程序加载pdb文件,所以无法做到。并且 Start without Debugging 不会加载 pdb 文件以使其正常工作。

作为建议

您必须同时通过attach to process启动一个新的vs实例来调试项目。

使用第二个建议即可实现。

1) 首先,你应该检查你的额外程序:

start external program 是您的Amibroker.exe 的完整路径,命令行参数 包含您在 VS 中当前项目 amibroker 插件的名称。

然后,取消选中工具-->选项-->调试下的“仅启用我的代码”选项-->常规

2) 其次,记得在你的cs文件的Main函数下添加Debugger.Launch();,如下所示:

 static void Main(string[] args)
        {
            Debugger.Launch();

            //add any code here

        }

3) 第三,点击Start Debugging然后打开Debug-->Windows-->Modules 然后搜索任何关于Amibroker 的dll 然后右键单击它们-->始终自动加载

4)第四,停止Debug进程,然后删除binobj文件夹。之后,再次点击Start Debugging,稍等片刻,即可看到Choose the Just-In-Time Debugger窗口。您应该选择 VS2019 IDE 并通过attach into process 使用当前项目启动一个新的 vs 实例。并且有了它,你可以单步进入断点调试代码。

或者您可以尝试我的第二个建议来自动启动该过程。

注意:第二个建议将通过 Attach to Process 与您的 amibroker 插件项目同时创建一个新的 VS 实例。

=============================================

另外,如果您仍然遇到同样的问题,请尝试在扩展程序菜单下禁用任何第三方扩展程序-->管理扩展程序检查是否有什么原因造成的。

另外重置所有 VS 设置 工具-->选项-->导入和导出设置-->重置所有设置,然后禁用选项启用仅我的代码选项

还有,还有a similar issue about it

【讨论】:

  • 谢谢!有效 :) 。但现在我遇到了另一个问题。无法加载文件或程序集“System.Text.Json,Version=4.0.1.1,Culture=neutral,PublicKeyToken=cc7b13ffcd2ddd51”。我已经通过 nuget 安装了 System.Text.Json。我的代码在我通过控制台项目运行时有效。但是当我编译成 dll 并在 amibroker 中使用它时,就会出现上述错误。你能给我指出正确的方向吗?
  • 您安装了哪个版本的System.Text.Json,能否与我们分享整个错误?
  • 一个建议,尝试在app.config文件下添加bindredirect:&lt;dependentAssembly&gt; &lt;assemblyIdentity name="System.Text.Json" publicKeyToken="xxxxxxxxxx" culture="neutral" /&gt; &lt;bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" /&gt; &lt;/dependentAssembly&gt;
  • 安装的版本是 4.7.1。我确实在我的 app.config 文件中提到了以下内容: 这也没有帮助。
  • 我现在已将完整的错误添加到我的问题中。还添加了 packages.config 条目。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-07-17
  • 1970-01-01
  • 2018-02-14
  • 2019-09-25
  • 2020-05-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多