English 中文(简体)
Getting debugger context in C# interactive
原标题:

C# Interactive seems a lot more powerful than the Immediate Window (at least it handles lambda expressions that are often used in LINQ - see Visual Studio debugging "quick watch" tool and lambda expressions), but it looks like it can t be used as a replacement as it doesn t know about the debugger context. Is there a way to have access to the debugger context?

I ve seen Getting debugger context in F# interactive and it might require the same things, but maybe there are new/different things available.

http://extendedimmediatewin.codeplex.com/ could be useful but looks quite dead, although someone said on Oct 18 2011 that he was planning to port it to VB.Net ( http://extendedimmediatewin.codeplex.com/discussions/75589 ).

最佳回答

Disclaimer: I work for Microsoft on the Roslyn team.

Unfortunately, we don t have a way to get the debugger context right now. We are aware that it would useful, and as we get more of the core deliverables for Roslyn completed we hope to investigate more and see what can be done.

问题回答

Not a complete solution, but in VS2015, after you ve run Initialize Interactive with Project, you can use Debug > Attach to Process to connect to the InteractiveHost.exe process.

You can then debug functions from your project. You won t be able to debug one-off functions in the Interactive window, though, as Kevin explained.

As as side note, https://stackoverflow.com/a/40650343/467110 points out that you may have to have a C# Interactive window open before you open your solution in order to successfully Initialize Interactive with Project

Inside C# Interactive you can run

System.Diagnostics.Debugger.Launch();

to request a debuger, whereby you will get a window asking you to choose one of the open Visual Studio instances or a new instance to attach. Assuming you used "Load Interactive with the Project" option of Visual Studio - any breakpoints in the open Solution will now be hit when code is ran by Interactive.

If you need the debugger without pre-existing code - you can now insert

System.Diagnostics.Debugger.Debug();

calls into the code you put into Interactive (but it does have to go in one chunk , i.e. one press of enter ), and you will be able to examine local vars via locals window and run code against interactive context via immediate window.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签