问题
When I debug an ASP.NET 5 web application it hits my breakpoints, but I cannot watch the contents of variables created locally.
Example code from startup.cs using empty project as template:
public void Configure(IApplicationBuilder app)
{
app.UseIISPlatformHandler();
var dummy = DateTime.Now;
app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World! " + dummy);
});
}
When I put a breakpoint on "app.Run(...." it hits the breakpoint but I cannot see the content of variable dummy. If I add dummy to Watch it says "error CS0103: The name 'dummy' does not exist in the current context". Although I can see the contents of DateTime.Now, which gives me the exact Date and Time every time I hover it. The same happens when I put a breakpoint in an MVC controller and watch variables overthere.
I was following a Pluralsight course and I also have this with the project I created while following that course, as well with the example files that come with the course.
During debug VS2015 is attached to the dnx.exe process In the video I see the VS2015 is attached to the IISExpress.exe process. But that course is from nov. 2015 perhaps something changed in the meanwhile.
Reboot of machine didn't help.
This is my first question over here, if more info is needed please let me know, and I'll do my best to provide.
回答1:
I've found the answer. Sometimes a night of rest does miracles.
I did a Google search on 'error CS0103: The name does not exist in the current context debug'. Without the word 'debug' you get a lot of results that don't help. I've found the following site: https://connect.microsoft.com/VisualStudio/feedback/details/1038150/visual-studio-2015-debugger-doesnt-recognize-a-variable
The answer is: Menu > Debug > Options, "Use Managed Compatibility Mode". Checked that option and it worked for me. Also for the project I was working on.
回答2:
Been searching the whole day for this. Enabling Use Managed Compatibility Mode did the trick. It allowed me to quickwatch the contents of my class, so that I could see that one of my get methods was referencing itself instead of the class attribute. Silly typo that broke my application. So I agree that this is a workaround and doesn't solve the underlying issue, but it helps finding it!
来源:https://stackoverflow.com/questions/36603791/cannot-watch-contents-of-variables-when-debuggin-asp-net-5-iis-express