简体   繁体   English

调试 Bricscad 插件 - 所选调试引擎不支持任何代码

[英]Debugging Bricscad plug-in - no code supported by selected debug engine

I am making a plug-in for Bricscad which is basically a dll that is used by the application.我正在为 Bricscad 制作一个插件,它基本上是应用程序使用的 dll。 This plug-in uses both console commands and WPF windows.此插件使用控制台命令和 WPF windows。 When I try to debug it and set breakpoints there is strange behaviour - if the code was called by the command it stops at the breakpoint and it is possible to debug it.当我尝试调试它并设置断点时,会出现奇怪的行为 - 如果代码是由命令调用的,它会在断点处停止并且可以调试它。 However if I open one of my WPF windows and code in question is triggered from it(ie by pressing a button) it still breaks at the breakpoint however all I get is this message: "Your app has entered a break state, but no code is currently executing that is supported by the selected debug engine (eg only native runtime code is executing)."但是,如果我打开我的 WPF windows 并从中触发有问题的代码(即通过按下按钮)它仍然在断点处中断,但我得到的只是这条消息:“您的应用程序已输入中断 Z9ED39E2A569428,但没有代码当前正在执行选定的调试引擎支持的(例如,只有本机运行时代码正在执行)。” This happens in the scope of a single dll.这发生在单个 dll 的 scope 中。 dll was built with 4.5.1 .NET framework. dll 是用 4.5.1 .NET 框架构建的。

I have checked the modules from studio - dll is loaded as well as symbols for it.我已经检查了工作室的模块 - dll 已加载以及它的符号。 I have also tried to uncheck Just My Code option but to no effect.我也尝试取消选中“仅我的代码”选项,但没有效果。 I have checked the threads - in both cases the code was executing in main thread.我检查了线程——在这两种情况下,代码都是在主线程中执行的。 The only difference that I see is that this message only appears if code is called from WPF window.我看到的唯一区别是,仅当从 WPF window 调用代码时才会出现此消息。

Here is an example of xaml file that is used.这是使用的 xaml 文件的示例。

<Window x:Class="Plugin.Window"
    Title="Window"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    mc:Ignorable="d"
    MaxHeight="400"
    MinHeight="350"
    Width="400"
    MinWidth="400" Height="350">

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary 
              Source="pack://application:,,,/Resource;component/AppDictonary.xaml">
            </ResourceDictionary>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window.Resources>


<StackPanel Orientation="Vertical" Margin="5">
    <Button x:Name="_startButton" Content="Start" Width="100" Click="ButtonStart_Click" />
</StackPanel></Window>

And the function called by WPF以及由 WPF 调用的 function

    private void ButtonStart_Click(object sender, RoutedEventArgs e)
    {
        Foo();
    }

If a breakpoint in Foo is triggered by a console command in Bricscad the debug is fine.如果 Foo 中的断点由 Bricscad 中的控制台命令触发,则调试很好。 But if its called from ButtonStart_Click the message manifests.但是,如果它是从 ButtonStart_Click 调用的,则消息清单。

What could be the possible cause of this message?此消息的可能原因是什么? Have anyone encountered this behaviour(maybe in some other dlls)?有没有人遇到过这种行为(可能在其他一些 dll 中)?

Maybe it is too late for you:D, but not for future readers.也许对你来说太晚了:D,但对未来的读者来说不是。

Description:描述:

Problem that you encountered is that source was not available on breakpoint in method which is invoked by some event (i used WindowsForms, but assume same sh*t is with WPF).您遇到的问题是源在某个事件调用的方法中的断点上不可用(我使用了 WindowsForms,但假设与 WPF 相同)。
But, it happens only when displaying Form/Window as modal - if you display it as modeless, then it works.但是,只有在将窗体/窗口显示为模式时才会发生这种情况 - 如果将其显示为无模式,则它可以工作。 (Form,Show() - modeless. Form.ShowDialog() - modal) (Form,Show() - 无模式。Form.ShowDialog() - 模式)

Solution解决方案

To debug BricsCAD in form code, try setting useLegacyV2RuntimeActivationPolicy="false" in your bricscad.exe.config file要在表单代码中调试 BricsCAD,请尝试在 bricscad.exe.config 文件中设置 useLegacyV2RuntimeActivationPolicy="false"

From this link -> https://forum.bricsys.com/discussion/comment/25822/#Comment_25822从这个链接-> https://forum.bricsys.com/discussion/comment/25822/#Comment_25822


Edit:编辑:

Important I spent several hours debugging StackOverflowException followed by process crash and close, while running tests from NUnit Console (it was nasty, i had to debug with WinDbg and to inspect dump files).重要的是,我花了几个小时调试 StackOverflowException,然后是进程崩溃并关闭,同时从 NUnit 控制台运行测试(这很讨厌,我不得不使用 WinDbg 进行调试并检查转储文件)。

Turned out changing this configuration made all those problems.结果发现更改此配置会导致所有这些问题。 So, keep it "false" only while you really want to debug code inside Windows Forms, otherwise switch to "true".所以,只有当你真的想在 Windows Forms 中调试代码时,才将其保持为“假”,否则切换为“真”。


Here is code which i use for switching this config on and off (in Visual Studio/Tools you can add new commands (enable/disable) with "External tools..." with selecting new.exe with arguments)这是我用于打开和关闭此配置的代码(在 Visual Studio/Tools 中,您可以使用“外部工具...”添加新命令(启用/禁用),并选择带有参数的 new.exe)

static void Main(string[] args)
    {
        string bricscadFolder = @"C:\Program Files\Bricsys\";
        bool enableFormDebugging = true;
        if (args != null && args.Length > 1)
        {
            bricscadFolder = args[0];
            enableFormDebugging = args[1] == "true";
        }

        var folders = Directory.GetDirectories(bricscadFolder);
        foreach(var folder in folders)
        {
            string file = $"{folder}\\bricscad.exe.config";
            if (File.Exists(file))
            {
                string content = File.ReadAllText(file);
                string replacement = $"useLegacyV2RuntimeActivationPolicy=\"{(enableFormDebugging ? "true" : "false")}\"";
                string pattern = @"useLegacyV2RuntimeActivationPolicy\s*=\s*""(true|false)""";
                Regex regex = new Regex(pattern);
                string result = regex.Replace(content, replacement);
                try
                {
                    File.WriteAllText(file, result);
                }
                catch(UnauthorizedAccessException e)
                {
                    Console.Write($"{file} is protected! Give it Write permission for User.");
                    Console.ReadLine();
                }
            }
        }
    }

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

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