Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow use of AdhocWorkspace within custom debug visualizer #32568

Open
zspitz opened this issue Jan 17, 2019 · 1 comment
Open

Allow use of AdhocWorkspace within custom debug visualizer #32568

zspitz opened this issue Jan 17, 2019 · 1 comment
Assignees
Labels
Area-IDE Concept-API This issue involves adding, removing, clarification, or modification of an API. Question
Milestone

Comments

@zspitz
Copy link

zspitz commented Jan 17, 2019

Version Used:
Microsoft.CodeAnalysis v. 2.10.0

Steps to Reproduce:

  1. Create a visualizer that calls new AdhocWorkspace on the debuggee side:
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);
        }
    }
}
  1. Write code with the target type of the visualizer:
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;

            // this call forces Microsoft.VisualStudio.DebuggerVisualizers.dll to be loaded
            var visualizerHost = new VisualizerDevelopmentHost(null, typeof(TestVisualizer));

            Console.ReadKey(true);
        }
    }
}
  1. Hover over the expr variable, click on the arrow next to the magnifying glass, and select "Test Visualizer"
    Choose the "Test Visualizer"

Expected Behavior:

Display the WPF window with data from the serialized visualizer data class:

screenshot2

Actual Behavior:
A window pops up with the following message:

Unable to perform function evaluation on the process being debugged.

Additional information

The function evaluation requires all threads to run.

screenshot3

Additional information
I know this is happening at the AdhocWorkspace constructor, because a throw new NotImplementedException() before the constructor shows a different message, but not after the constructor.

SO post requesting a workaround -- https://stackoverflow.com/questions/54171930/this-function-requires-all-threads-to-evaluate-after-new-adhocworkspace-wi

@vatsalyaagrawal vatsalyaagrawal added Question Area-IDE Concept-API This issue involves adding, removing, clarification, or modification of an API. labels Jan 17, 2019
@jinujoseph jinujoseph added this to the Backlog milestone Jan 17, 2019
@zspitz
Copy link
Author

zspitz commented Jan 20, 2019

@vatsalyaagrawal @jinujoseph @tmat I am describing a use case for the code generation features of Roslyn (inside a debugging visualizer), in which there is a problem when calling the AdhocWorkspace constructor. Is it appropriate to label this as "Question"?

The question on SO is "how can I work around this incompatibility?" and is indeed a question. This issue is a request to fix the source of the incompatibility, and thus isn't really a question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Concept-API This issue involves adding, removing, clarification, or modification of an API. Question
Projects
None yet
Development

No branches or pull requests

4 participants