调试器可视化工具不工作? 难道我注册错了?

发布于 2024-07-10 15:24:03 字数 1393 浏览 7 评论 0原文

我在 VS2008 中创建了一个调试器可视化工具。 我在同一个 .dll 中创建了两个类:-

  • BinaryDataDebuggerVisualizer
  • ImageDebuggerVisualizer

图像类工作正常(例如,放大镜出现在调试模式下),但不适用于 byte[] 类 (BinaryDataDV)。 我的可视化工具所做的是将二进制数据显示为模式窗口中的图像(如果数据是合法图像)。 我在发布模式下编译为代码,然后将 .dll 放入 C:\Users\\Documents\Visual Studio 2008\Visualizers

这是我用来“定义”可视化的代码...

使用

System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Microsoft.VisualStudio.DebuggerVisualizers;
using Foo.DebuggerVisualizers;  

[assembly: DebuggerVisualizer(
    typeof (BinaryDataDebuggerVisualizer),
    typeof (VisualizerObjectSource),
    Target = typeof (byte[]),
    Description = "Binary Data to Image Visualizer")]

namespace Foo.DebuggerVisualizers
{
    public class BinaryDataDebuggerVisualizer : DialogDebuggerVisualizer
    {
        protected override void Show(IDialogVisualizerService windowService,
           IVisualizerObjectProvider objectProvider)
        {
            ... my code in here
        }
     }
}

我制作了一个单元在调试器可视化解决方案中进行测试,该解决方案会启动并测试代码..它会正确显示合法(也是非法)图像文件。 所以我相信代码没问题。

当我处于真正的解决方案中时,这就是我正在做的事情(当我在调试模式下将鼠标悬停在变量上时,我希望放大镜显示)。

byte[] data = File.ReadAllBytes("Chick.jpg");

然后,当我在调试时暂停代码时,将鼠标悬停在变量 data 上(使用断点)。

没有沙漏:(

有人知道哪里出了问题吗?

I have created a debugger visualizer in VS2008. There are two classes i've made, in the same .dll :-

  • BinaryDataDebuggerVisualizer
  • ImageDebuggerVisualizer

The image one works fine (eg. the magnify glass appears in debug mode) but not for the byte[] one (BinaryDataDV). What my visualizer does is display the binary data as an image in a modal window (if the data is a legit image). I compiled to code in Release mode, then dropped the .dll into C:\Users\\Documents\Visual Studio 2008\Visualizers

this is the code that i used to 'define' the vis...

using

System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Microsoft.VisualStudio.DebuggerVisualizers;
using Foo.DebuggerVisualizers;  

[assembly: DebuggerVisualizer(
    typeof (BinaryDataDebuggerVisualizer),
    typeof (VisualizerObjectSource),
    Target = typeof (byte[]),
    Description = "Binary Data to Image Visualizer")]

namespace Foo.DebuggerVisualizers
{
    public class BinaryDataDebuggerVisualizer : DialogDebuggerVisualizer
    {
        protected override void Show(IDialogVisualizerService windowService,
           IVisualizerObjectProvider objectProvider)
        {
            ... my code in here
        }
     }
}

I've made a unit test in the debugger visualizer solution, which fires up and test the code .. which it correctly shows a legit (and also illegal) image files. so i believe the code is ok.

When i'm in my real solution, this is what i'm doing (where i expect the magnify glass to show, when i'm hovering over the variable in debug mode).

byte[] data = File.ReadAllBytes("Chick.jpg");

then i hover over the variable data when i've paused the code while debugging, on that line (using a breakpoint).

No hourglass :(

anyone have any ideas to what is wrong?

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

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

发布评论

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

评论(2

鹊巢 2024-07-17 15:24:03

不幸的是这是不可能的。 调试器可视化工具框架存在限制,无法在数组类型或对象上运行。

http://msdn.microsoft.com/en-us/library/e2zc529c。 aspx

页面引用:

“您可以为任何托管类的对象编写自定义可视化工具
除了对象或数组”

Unfortunately this is not possible. There is a limitation in the Debugger Visualizer framework that prevents them from functioning on array types or object.

http://msdn.microsoft.com/en-us/library/e2zc529c.aspx

Quote from the page:

"You can write a custom visualizer for an object of any managed class
except for Object or Array"

并安 2024-07-17 15:24:03

此处描述了解决方法:https://joshsmithonwpf.wordpress.com/2008/01/ 由乔什·史密斯撰写。

在那篇文章中,他描述了一种特定可视化工具的使用(称为 Mole,它似乎不再存在); 我稍微删减了该文本,只留下通用概念。

...

问题的关键是 Visual Studio 不允许我们
将 DebuggerVisualizer 属性应用于 [自定义可视化工具] 并
指定它适用于任何继承自 System.Object 的对象。
...我想出了一个简单的方法来解决这个人工问题
Visual Studio 施加的限制。

Visual Studio 毫不犹豫地允许我们指定[自定义
Visualizer] 可用于可视化 System.WeakReference 对象。
由于 WeakReference 基本上只是一个薄薄的包装器
对象,我们使用 WeakReference 作为特洛伊木马来走私任何对象
经过 Visual Studio 哨兵...一旦 [自定义可视化工具] 获得
持有我们包裹在我们的对象周围的WeakReference
实际上想要可视化,它打开对象并将其显示在
UI,在此过程中丢弃WeakReference。 记住
我们仅使用 WeakReference 作为走私任何内容的容器
对象进入[可视化工具],我们不使用该类
预期和记录的目的。

所以这一切都很好,但如果你
必须停止调试会话才能编辑代码并创建
这些WeakReferences...这就是Watch窗口进入的地方
图片。 您可以在 Watch 窗口中创建一个 WeakReference,并传递
要可视化到其构造函数中的对象。 这是一个例子...:

“在此处输入图像描述"

在监视窗口中创建 WeakReference 后,我可以
只需单击放大镜图标即可打开[可视化工具]。

A workaround is described here: https://joshsmithonwpf.wordpress.com/2008/01/ written by Josh Smith.

In that article he was describing the use of a particular visualizer (called Mole, which no longer seems to exist); I've cut down that text somewhat to just leave the general purpose concepts.

...

The crux of the matter is that Visual Studio will not allow us to
apply the DebuggerVisualizer attribute to [a custom visualizer] and
specify that it works for any object that descends from System.Object.
... I figured out a simple way to work around this artificial
limitation imposed by Visual Studio.

Visual Studio has no qualms with allowing us to specify that [a custom
visualizer] can be used to visualize a System.WeakReference object.
Since WeakReference is basically just a thin wrapper around any
object, we use WeakReference as a Trojan horse to smuggle any object
past the Visual Studio sentries... Once [the custom visualizer] gets a
hold of the WeakReference we wrapped around the object that we
actually want to visualize, it unwraps the object and displays it in
the UI, throwing away the WeakReference in the process. Keep in mind
that we are only using WeakReference as a container to smuggle any
object into [the visualizer], we are not using that class for its
intended and documented purpose.

So that’s all well and good, but it would be a real nuisance if you
had to stop your debugging session just to edit your code and create
these WeakReferences... That’s where the Watch window enters the
picture. You can create a WeakReference in the Watch window, and pass
the object to visualize into its constructor. Here’s an example...:

enter image description here

Once the WeakReference has been created in the Watch window, I can
simply click on the magnifying glass icon to open [the visualizer].

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