15

I am working on .NET CORE 1.0 MVC 6 application and I stuck with the debugging point as it stopping hitting yesterday. with number of try I delete project and start again. First time it load symbols even due I have uncheck in Tool --> Debugging --> symbols, however it hit breakpoints. Now it only hitting C# class 'Startup.cs' if I choose 'Enable Just My Code' but in controller. I have Debug option from dropdown, not really sure why. Need help here.

enter image description here

enter image description here

enter image description here

I change as

Select Debug->Options->Debugging->General

Tick Enable .NET Framework source stepping.

but still no success

enter image description here

Module

enter image description here

Trying to Hit in Controller home class for MVC Core in Index and about

 public class HomeController : Controller
{
    public IActionResult Index()
    {
        var x = 2 + 3;

        return View();
    }

    public IActionResult About()
    {
        var x3 = 2 + 6;
        var xx = "dd";

        ViewData["Message"] = "Your application description page.";

        return View();
    }

Debugging output

enter image description here

K.Z
  • 5,201
  • 25
  • 104
  • 240
  • Do you get any output messages from the Output window? Please also check your debug Modules window. To make sure that it is not related to your VS settings, I suggest you reset your VS settings before you debug your app. For example, the project property "Optimize code" or others will impact the debugging. – Jack Zhai Nov 17 '16 at 01:14
  • it is complaining about symbols not loaded – K.Z Nov 18 '16 at 07:39
  • it was working fine until recently only work when I create new project and it hit breakpoints in controller class but once application close and re-open it doesn't hit debugging point, although it still hit debugging point for startup.cs. – K.Z Nov 18 '16 at 09:25
  • I believe it is complaining that symbols not been loaded as to test, I have created MVC 5 application and during debugging, the debugging red mark goes yellow, giving me symbols not loaded error message. – K.Z Nov 18 '16 at 09:25
  • i did reset visual studio but still same issue – K.Z Nov 18 '16 at 09:26
  • Is the code really called in your page loaded? Please also enable the Microsoft symbols server. Check your Debug->Windows->Modules window, which assembly met the loaded issue? Please share a screen shot about which line code you add the breakpoint. How about a default .NET core project? – Jack Zhai Nov 18 '16 at 10:02
  • I have update my question with screen shots – K.Z Nov 18 '16 at 11:45
  • it work when i create new project and hit all debugging point including in controller class but not any more in second and any after rebuild – K.Z Nov 18 '16 at 11:46
  • if you disable the option "'Enable Just My Code" under Tools -> Options -> Debugging -> General, and then clean and rebuild your project, how about the result? What I know is that if that option is enabled, the managed debugger will not load symbols for any modules that are optimized. You will see the Skipped loading symbols like your module window. Please also visit your project property->Build, not enable "Optimize code". Please check whether there are certain special references in your projects, for example, no that dll file in your project output path after you rebuild projects. – Jack Zhai Nov 19 '16 at 08:07
  • what about this issue? toxic:) Would you please share us the latest information about this issue? – Jack Zhai Nov 21 '16 at 08:24

6 Answers6

13

actually your screen shot was not the debug output, it was the build output.

If you disable the "Enable Just My Code", and enable/disable the Microsoft symbols Server under TOOLs->Options->Debugging->Symbols, and then debug your app after you re-open it, how about the result?

If I create a new app, the breakpoint was hit normally, if I re-open the solution, actually it still could hit the breakpoint, but it is very slow. Like the screen shot 1, if you visit the "debug" output window, it would list the symbols loaded one by one, after about 1min, it would hit the breakpoint like screen shot 2. Of course, I enabled the Microsoft symbols under TOOLS->Options->Debugging->Symbols and disabled the Enable Just My Code for the above steps.

So for your issue, one possible reason is that it just loads the symbols slowly, just wait for a moment.

enter image description here

enter image description here

Jack Zhai
  • 6,230
  • 1
  • 12
  • 20
  • 1
    Hi Jack, In my scenario debug is not working for only one controller that is "LoginController" but it is working for all other controllers. And the output is running on Debug mode only. Any idea about this? why only one controller not accepting the debug. Note: Whatever I am changing any code in the login controller that's not affecting also but I have verified that whether I have changed the code in right path or file. – Md Aslam Apr 15 '20 at 05:19
9

While Jack Zhai-MSFT's solution worked I still had some weird behavior: breakpoints were working partially. Found solution here that works perfectly: Breakpoint Failed to Bind - Visual Studio 2015 While the above link is loaded with tons of solutions in my case changing configuration from Release to Debug under Build menu Configuration Manager solved all my breakpoints related problems.

Richard Mneyan
  • 656
  • 1
  • 13
  • 20
  • 1
    I guess breakpoints are designed to work in Debug mode, and in Release mode they are skipped to speed up the process (but I'm just guessing). – Richard Mneyan Aug 03 '18 at 18:29
  • 2
    Breakpoints and debug mode work by generating specific assembly instructions that give your application the ability to be paused with breakpoints, when you build in release, those assembly instructions aren't generated, ergo there's nothing for the debugger to break on, so that's why you can have breakpoints set in release, but still not have your application actually break. – Trevor Hart Oct 16 '18 at 01:23
  • @TrevorHart - thanks, it's good to know how it works behind the scenes. – Richard Mneyan Oct 16 '18 at 13:48
5

I thought I was running into this same behavior except in my case it was caused by Temporal Coupling in the Startup.cs class of my .NET Core MVC application.

I had included my app.UseMiddleware() call below my app.UseMvc() call and because of this my middleware component would initialize but was never hit by requests coming into my application. Moving my call to app.UseMiddleware call above the app.UseMvc call fixed this and now my requests are being properly routed through my custom middleware.

app.UseMVC MUST BE THE LAST "app.Use()" call in the Configure method of your Startup.cs class

P. Roe
  • 2,077
  • 1
  • 16
  • 23
  • Thank you! Is this documented somewhere? – empz Jul 15 '19 at 11:47
  • Not that I know of. It's sort of implied here https://learn.microsoft.com/en-us/aspnet/core/fundamentals/middleware/?view=aspnetcore-2.2 – P. Roe Jul 15 '19 at 18:09
3

I faced the same problem and none of the above solutions worked. Finally I figured out below setting works like a charm.

Go to Tools->Options->Debugging->General->Uncheck "Use Managed Compatibility Mode" checkbox

Raj
  • 132
  • 3
1

This solved my problem -> Close visual studio. -> Deleting .vs folder reopen visual studio. Doing this solved the problem breakpoint couldn't be hit

Abdulhakim Zeinu
  • 3,333
  • 1
  • 30
  • 37
0

Worked for me by enabling following Debugging option "Enable .Net framework source stepping"