调试器可视化工具、ElementHost 和编辑并继续问题

发布于 2024-08-27 16:07:55 字数 1863 浏览 1 评论 0原文

我最近为我的应用程序中的一种自定义类型编写了一个适用于 Visual Studio 2008 的自定义调试器可视化工具。可视化工具的 UI 使用 WPF 编写,托管在元素宿主中,并使用 IDialogVisualizerService windowService 对象显示。

一切都运行良好,我的可视化工具加载并显示相关信息,但如果在加载可视化工具后尝试在我的应用程序中“编辑并继续”,Visual Studio 会崩溃,并且没有任何有用的错误消息。

在尝试调试此问题时,我从解决方案中删除了几乎所有代码,直到我仅使用 ObjectSource 序列化字符串并仅显示一个空元素主机,但在编辑并继续时仍然崩溃。如果我删除元素主机并显示 WinForms 控件或表单,则不会发生崩溃。

这是可视化器代码:

using System;
using System.Drawing;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using Microsoft.VisualStudio.DebuggerVisualizers;
using ObjectVisualizerShared;
using ObjectVisualizerUI;

namespace ObjectVisualizer
{
    public class Visualizer : DialogDebuggerVisualizer
    {
        protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
        {
            try
            {

                Stream stream = objectProvider.GetData();
                if (stream.Length > 0)
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    VisualizerNode node = (VisualizerNode)formatter.Deserialize(stream);
                    if (node != null)
                    {
                        VisualizerWindow window = new VisualizerWindow(node);
                        ElementHost host = new ElementHost();
                        host.Child = window;
                        host.Dock = DockStyle.Fill;
                        host.Size = new Size(800, 600);
                        windowService.ShowDialog(host);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Error!\n{0}", ex), "Object Visualizer");
            }
        }
    }
}

有什么想法吗?

I recently wrote a custom Debugger Visualizer for Visual Studio 2008 for one of the custom types in my application. The UI for the visualizer is written in WPF and is hosted in an element host and shown using the IDialogVisualizerService windowService object.

Everything works great, and my visualizer loads and shows the relevant information, but if try to "edit and continue" in my application after loading the visualizer, Visual Studio crashes with no useful error message.

In trying to debug this I removed almost all of my code from the solution to the point where I was only serializing a string with the ObjectSource and displaying just an empty element host and I still get the crash on edit and continue. If I remove the element host and show a WinForms control or form there is no crash.

Here is the Visualizer code:

using System;
using System.Drawing;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using Microsoft.VisualStudio.DebuggerVisualizers;
using ObjectVisualizerShared;
using ObjectVisualizerUI;

namespace ObjectVisualizer
{
    public class Visualizer : DialogDebuggerVisualizer
    {
        protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
        {
            try
            {

                Stream stream = objectProvider.GetData();
                if (stream.Length > 0)
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    VisualizerNode node = (VisualizerNode)formatter.Deserialize(stream);
                    if (node != null)
                    {
                        VisualizerWindow window = new VisualizerWindow(node);
                        ElementHost host = new ElementHost();
                        host.Child = window;
                        host.Dock = DockStyle.Fill;
                        host.Size = new Size(800, 600);
                        windowService.ShowDialog(host);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Error!\n{0}", ex), "Object Visualizer");
            }
        }
    }
}

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

日裸衫吸 2024-09-03 16:07:55

虽然我没有真正找到“正确”的修复方法,但我找到了可接受的解决方法。

我将可视化移动到一个完全独立的程序中,然后在调试器可视化器中,我在一个单独的进程中启动可视化程序,并使用命名管道将数据对象发送给它。

这运行良好,并且具有额外的优点,即可视化窗口在数据更改和调试会话中持续存在。

While I didn't really find a "proper" fix, I have found an acceptable workaround.

I moved my visualization into an entirely separate program, and then in my debugger visualizer I start the visualization program in a separate process and I send the data object to it using a named pipe.

This is working well, and has the added advantage that the visualization windows persist across data changes and debug sessions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文