简体   繁体   English

VS自定义可视化工具中的“ new AdhocWorkspace()”之后,“此函数需要所有线程进行评估”

[英]“This function requires all threads to evaluate” after `new AdhocWorkspace()` within VS custom visualizer

I am trying to write a visualizer that maps expressions in an expression tree to Roslyn syntax nodes , in order to generate code for the expression tree. 我正在尝试编写一个可视化工具, 以将表达式树中的表达式映射到Roslyn语法节点 ,以便为表达式树生成代码。 Part of the syntax tree generation is a call to the AdhocWorkspace constructor. 语法树生成的一部分是对AdhocWorkspace构造函数的调用。

When I run the visualizer using the VisualizerDevelopmentHost , everything works just fine: 当我使用VisualizerDevelopmentHost运行VisualizerDevelopmentHost ,一切正常:

using Microsoft.VisualStudio.DebuggerVisualizers;
using System;
using System.Linq.Expressions;

namespace _testVisualizer {
    class Program {
        [STAThread]
        static void Main(string[] args) {
            Expression<Func<bool>> expr = () => true;
            var data = new TestVisualizerData(expr);
            var visualizerHost = new VisualizerDevelopmentHost(data, typeof(TestVisualizer));
            visualizerHost.ShowVisualizer();

            Console.ReadKey(true);
        }
    }
}

But when I try to use the visualizer through the Visual Studio UI (by hovering over expr , clicking on the magnifying glass icon and choosing my visualizer), I get the following message: 但是,当我尝试通过Visual Studio UI使用可视化工具时(将鼠标悬停在expr ,单击放大镜图标并选择我的可视化工具),会收到以下消息:

Unable to perform function evaluation on the process being debugged. 无法对正在调试的进程执行功能评估。

Additional information 附加信息

The function evaluation requires all threads to run. 函数评估要求所有线程都运行。

I've identified the following as triggering the error: 我已确定触发错误的原因如下:

workspace = new AdhocWorkspace();

which assigns to the workspace field on my Mapper class ( source ). 分配给我的Mapper类( )上的workspace字段。

Why does calling the AdhocWorkspace constructor trigger this warning? 为什么调用AdhocWorkspace构造函数会触发此警告? How can I work around this? 我该如何解决?


This is an MCVE that demonstrates the issue: 这是演示此问题的MCVE:

using Microsoft.CodeAnalysis;
using Microsoft.VisualStudio.DebuggerVisualizers;
using System;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Controls;

[assembly: DebuggerVisualizer(typeof(_testVisualizer.TestVisualizer), typeof(_testVisualizer.TestVisualizerDataObjectSource), Target = typeof(System.Linq.Expressions.Expression), Description = "Test Visualizer")]

namespace _testVisualizer {
    public class TestVisualizer : DialogDebuggerVisualizer {
        protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider) {
            var data = (TestVisualizerData)objectProvider.GetObject();
            var txt = new TextBlock();
            txt.SetBinding(TextBlock.TextProperty, "Status");
            var window = new Window {
                DataContext = data,
                Content = txt
            };
            window.ShowDialog();
        }
    }

    [Serializable]
    public class TestVisualizerData {
        public TestVisualizerData() { }
        public TestVisualizerData(System.Linq.Expressions.Expression expr) {
            var workspace = new AdhocWorkspace();
            Status = "Success";
        }
        public string Status { get; set; }
    }

    public class TestVisualizerDataObjectSource : VisualizerObjectSource {
        public override void GetData(object target, Stream outgoingData) {
            var expr = (System.Linq.Expressions.Expression)target;
            var data = new TestVisualizerData(expr);
            base.GetData(data, outgoingData);
        }
    }
}

Perhaps the AdhocWorkspace alternate constructor could be leveraged to use the SyntaxNode API in a single thread. 也许可以利用AdhocWorkspace 备用构造函数在单个线程中使用SyntaxNode API。

I've filed an issue . 我提了一个问题

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

相关问题 VS2015 Watch LINQ var错误:函数评估需要运行所有线程 - VS2015 Watch LINQ var Error: The function evaluation requires all threads to run 功能评估需要运行所有线程 - The function evaluation requires all threads to run 什么是 function 评估需要所有线程运行? - What is the function evaluation requires all threads to run? ASP.NET MVC或更多VS调试问题-EF / Sql函数评估要求所有线程都运行[保持] - ASP.NET MVC or more of a VS debugging issue - EF/ Sql The function evaluation requires all threads to run [on hold] 调试期间的 Visual Studio:function 评估需要所有线程运行 - Visual Studio during Debugging: The function evaluation requires all threads to run 懒 <T> :“功能评估需要所有线程运行” - Lazy<T>: “The function evaluation requires all threads to run” 虚拟列表 <T> :“功能评估需要所有线程运行” - virtual List<T> :“The function evaluation requires all threads to run” 无法在VS19中加载LLBL Gen Pro的自定义可视化程序 - Unable to load custom visualizer of LLBL Gen Pro in VS19 创建一个对所有Object进行操作的C#VS2010 Visualizer - Creating a C# VS2010 Visualizer that operates on all Object 如何在没有“函数求值要求所有线程都运行”的情况下在后台调用方法 - How can I call a method in the background without “The function evaluation requires all threads to run”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM