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