Visual Studio 2019 自定义可视化调试工具的坑

Visual Studio  自定义可视化调试工具已有大量文章介绍,这里不再啰嗦。如果不懂建议看看https://www.cnblogs.com/cyq1162/p/4551652.html 

https://docs.microsoft.com/en-us/visualstudio/debugger/walkthrough-writing-a-visualizer-in-csharp?view=vs-2019

本人也胡乱弄了个可视化调试 显示一组中间计算曲线,开始一切顺利,技术难度也不大。

代码及运行效果如下:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using FirstLineTamping.Infrastructure.Measure;
using LineView;
using Microsoft.VisualStudio.DebuggerVisualizers;
[assembly: System.Diagnostics.DebuggerVisualizer(typeof(TMGC_DV.TMGC_Visualizer), typeof(VisualizerObjectSource), Target = typeof(FirstLineTamping.Infrastructure.Measure.MeasSet), Description = "TMGC MeasSet Visualizer")]
[assembly: System.Diagnostics.DebuggerVisualizer(typeof(TMGC_DV.TMGC_Visualizer), typeof(VisualizerObjectSource), Target = typeof(FirstLineTamping.Infrastructure.Measure.VerschArray), Description = "TMGC VerschArray Visualizer")]
[assembly: System.Diagnostics.DebuggerVisualizer(typeof(TMGC_DV.TMGC_Visualizer), typeof(VisualizerObjectSource), Target = typeof(FirstLineTamping.Contract.Entities.Offsets.TrackOffset), Description = "TMGC TrackOffset Visualizer")]
[assembly: System.Diagnostics.DebuggerVisualizer(typeof(TMGC_DV.TMGC_Visualizer), typeof(VisualizerObjectSource), Target = typeof(List), Description = "TMGC List Visualizer")]
[assembly: System.Diagnostics.DebuggerVisualizer(typeof(TMGC_DV.TMGC_Visualizer), typeof(VisualizerObjectSource), Target = typeof(FittingMeasure.PosValueArray), Description = "TMGC PosValueArray Visualizer")]
namespace TMGC_DV
{ 
    public class TMGC_Visualizer : DialogDebuggerVisualizer
    {
        protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
        {
            var s = objectProvider.GetObject();

            Db_Form f = new Db_Form();
            Debug.WriteLine("DialogDebuggerVisualizer :" + objectProvider.ToString ());
            if (s is FirstLineTamping.Infrastructure.Measure.MeasSet)
            {
                f.AddMeasGrph(s as FirstLineTamping.Infrastructure.Measure.MeasSet);
                f.Text = "Measure.MeasSet";
            }
            if (s is FirstLineTamping.Infrastructure.Measure.VerschArray)
            {
                f.AddMeasGrph(s as FirstLineTamping.Infrastructure.Measure.VerschArray);
            }
            if (s is FirstLineTamping.Contract.Entities.Offsets.TrackOffset)
            {
                f.AddMeasGrph(s as FirstLineTamping.Contract.Entities.Offsets.TrackOffset);
            }
            if (s is List )
            {
                f.AddMeasGrph(s as List);
            }
            if (s is FittingMeasure.PosValueArray)
            {
                f.AddMeasGrph(s as FittingMeasure.PosValueArray);
                f.Text = "PosValueArray";
            }
            f.ShowDialog();

        }
        public static void TestShowVisualizer(object objectToVisualize)
        {
            VisualizerDevelopmentHost visualizerHost = new VisualizerDevelopmentHost(objectToVisualize, typeof(TMGC_Visualizer));
            visualizerHost.ShowVisualizer();
        }
    }
}

运行效果 

Visual Studio 2019 自定义可视化调试工具的坑_第1张图片

昨天更新了到了 Microsoft Visual Studio Professional 2019 版本 16.4.5

我的工具就不会工作了,总是显示:

Visual Studio 2019 自定义可视化调试工具的坑_第2张图片

在网上搜索半天发现:Visual Studio Professional 2019 要求被调试对象是 “可信任"程序,否则不能使用自定义调试工具!

折腾半天!

 

你可能感兴趣的:(经验)