Debugging not hit breakpoints in .NET CORE MVC 6 application - asp.net-core-mvc

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.
I change as
Select Debug->Options->Debugging->General
Tick Enable .NET Framework source stepping.
but still no success
Module
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

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.

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.

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

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

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

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

Related

Getting started with Watin

I am trying to do the quick start example, I bring in the ref's using NuGet in VS2010, I scrape the sample code on the webpage, I see my NUnit Session window, I click the green arrow, but the browser doesn't get invoked (doesn't start). What am I missing?
using System;
using NUnit.Framework;
using WatiN.Core;
namespace FirstWatinProject
{
[TestFixture]
public class Class1
{
[Test]
[STAThread]
public void SearchForWatiNOnGoogle()
{
using (var browser = new IE("http://www.google.com"))
{
browser.TextField(Find.ByName("q")).TypeText("WatiN");
browser.Button(Find.ByName("btnK")).Click();
Assert.IsTrue(browser.ContainsText("WatiN"));
}
}
}
}
I am getting the following error in NUnit Sessions window;
SearchForWaitOnGoogle Failed: System.IO.FileNotFoundException: Could
not load file or assembly 'Interop.SHDocVw, Version=1.1.0.0,
Culture=neutral etc...
Okay, solved the error, it is as the following other overflow thread concludes;
WatiN System.IO.FileNotFoundException Interop.SHDocVw
BUT, a key action in the sequence is to build the class library project AFTER setting the Interop.SHDocVw dlls' 'Embed Interop Types' property to 'False';
Then you can hit the green arrow in NUNIT Sessions window and you will see the IE browser startup after a second or two. Simply click it and you will see whatever actions you have programmed.
God is in the details!
Setting the Interop.SHDocVw, Microsoft.mshtml dlls' 'Embed Interop Types' property to 'False';
Of course Visual Studio would give you warnings on how to amend.
The Use of Nugget Package Manager
Check for the availability of Interop.SHDocVw.dll,
Make sure that your project has a reference to Interop.SHDocVw.dll and the dll is present in the Bin/Release Folder depending upon how you are running..
Just select Build from the main menu...then select Configuration Manager. In the list select you project and change its Plateform 'Any CPU' etc to x86.
If you have only Only CPU option, you can use ... option when chosing platform and create new setting, that is for X86 platform and then choose it.
ref:
Change target to x86 in VS2010
I already had a reference to Interop.SHDocVw. The easiest fix for me was simply changing .NET from 4.5 to 3.5 in Visual Studio settings. After making the change, it worked fine.

How to debug in VS instead of JIT Debugger?

UPDATE: navigating to the process via menu:DEBUG / Attach Process / iexplore.exe shows "Automatic: Silverlight code". i.e. VS 2010 already attached to the process. Why doesn't it go to debug view?
I have a frustrating debug behaviour going on on my laptop which I'd like to fix. I was following along with the demo called Silverlight TV 46: What's Wrong with my WCF Service?
On my computer, I noticed that putting throw new ArithmeticException() in the RIA service causes the just-in-time debugger to get involved (a bad thing -- I want VS). I can put a break point on the the throw new ArithmeticExpression() line, and VS stops as it normally does. Press F10, and I still get the just-in-time debugger kicking in.
On Yvor's computer (the presenter in the Ch 8 link above), the visual studio debugger kicks in instead of the just-in-time one. What am I doing wrong? Could having Redgate Reflector installed previously have caused this (it is gone now).
ERROR:
Visual Studio Just-In-Time Debugger
Code: 4004
Category: ManagedRuntimeError
Message: System.Reflection.TargetInvocationException: An exception occurred during the operation, making the result invalid.
Check ...
Possible Debuggers:
New instance of MS VS 2010,
New instance of VS 2008.
[checked] Set currently selected debugger as the default.
[unchecked] Manually choose the debugging engines
Action: Hit Yes.
2nd ERROR:
Unable to attach to the crashing process. A debugger is already attached.
I've spent several hours looking for a way to solve this.
Browser is IE9 / Silverlight 4.
Previously, I started starting the silverlight app directly via the VS2010 environment... but then decided to get more deployment compliant (again).
http://msdn.microsoft.com/en-us/library/cc838267(VS.95).aspx
Down the bottom they mention repairing from control panel / VS2010. Did that. Waited for ages, made coffee, did something else. Finally complete. Problem sill there. Included this step just-in-case the fix is cumulative (you get superstitious after a while with these things).
I then deleted zap files, switched startup page from html to the aspx one. Wired aspx to the xap (it wasn't pointing to the /debug/ folder). [note: looks like you can remove the debug via Silverlight Project / build / Output path: Replace Bin\Debug\ with Bin. With Silverlight I feel that the relative Uri path should match up to your html / aspx files no matter what -- wheather you are in Debug or Release.
project properties / Web / Specific Page
debugging works again!
Did .html stop debugging? Casual inspection reveals the same javascript stuff firing up Silverlight. On the surface it looks the same. hmmm. I guess it isn't.
... here are a few extra things to look at for those who still have issues (I may as well list them
while they are fresh in my mind).
project / properties / Web / Debuggers: I now only have Silverlight checked. ASP.Net is not checked any more. (Not sure if this influences my result at this stage)
make sure your web project points to the silverlight project in project / properties / Silverlight Applications. This ensures that the silverlight project's binary "xap" is copied to a folder within the Web Site / Web App. Note: hitting the add button reveals a destination folder (should be ClientBin).
Your build configuration will add an additional sub foler e.g. debug.
Make sure your .aspx or .html files have the right path. For me, I just included the .ClientBin/debug/ folder. I don't think this is deploy friendly, so I will search for a better way later.
IE9 settings.
[X] Disable script debugging.
[X] Disable script debugging (Other)
[ ] Display notification about a script error
[ ] Show friendly HTTP error message
Again, unsure if these later setting have an impact.
Lastly, there's something that I forget about sometimes. Be sure to check Debug VS2010 / Exceptions / Common language Runtime. This ups the ability to catch exceptions.
I had a similar problem, but the above did not resolve it. However, starting the application without debugging (Ctrl-F5) and triggering the exception would allow me to select the Visual Studio instance that I started the application from. Amazingly, I got a sensible stack trace and resolve the problem within a few minutes.

VS2010 debugger debugging old code

I have a console app, and a class library.
I'm making changes to the class library (adding new methods, changing what methods do, etc) - Just regular stuff - nothing fancy.
In the console app - I'm calling methods from the class library - obviously to test the class library methods - again no rocket science here!
Both projects are targeting Framework 3.5 (This is because I have Sharepoint 2010 being referenced in class library)
Now:
When I debug the app using F5 - I've set a break point in the console app. When it steps through to the class library (using F11) I get a message saying source code has changed in a pretty lengthy dialog. If I click cancel - it then says No source code available.
I have found a work around to right click on project in solution explorer, then select debug -> create new instance.
But this is strange, never had this issue before, what can I do to get the debugger behaving normally. By normally I mean every time I hit F5 it should understand that the source code in the class library will almost surely have changed and I don't want any nags about this, or break point conditions never being met.
On a side note, never had this issue before, so an explanation as to why its happening would help a lot.
Thanks in advance
Update: the short version
Why do I have to manually tell the debugger to "create new instance" everytime I want to debug? If I don't hitting f5 debugs the source code of the last successful debug session.
Maybe your console application doesn't build second project? Try verifying that newest version of library is called.

Another knack on the "Dialogs must be user-initiated" Security Exception in Silverlight printing

I get the infamous "Dialogs must be user-initiated" Security Exception when I try to print some stuff in Silverlight. As you can see, the dialog is as user-initiated as can be:
John Papa couldn't help me much out neither, because I don't have any breakpoint set. Mr MSDN thinks it could also be that I'm just taking too long, but this is a demo application just as simple as can be.
Any ideas? I guess it's a Visual Studio quirk, maybe some extensions interfering, as things seems to work when I launch the application outside of it. I first thought maybe the Code Contracts are interfering with their IL weaving, but they are deactivated for this project.
Update: This is just a simple Silverlight application that runs locally from the file system. When I do "Start debugging", Visual Studio creates a hosting HTML file containing the Silverlight app in the Debug resp. Release folder of the project, launches the Internet Explorer with that HTML file and attaches the debugger to it.
Update 2: I also get the same error when I create a web project to host the Silverlight app and create a virtual directory for it on IIS.
I might also want to add that I don't have problems with printing in other Silverlight projects regardless of their hosting scenarios.
Update 3: I downloaded FireFox and it works, I don't get the error when I debug with it. So it seems to have to do with my IE8. I uploaded the solution:
http://dl.dropbox.com/u/10401470/Code/Demos/PrintingDemo.zip
I wonder if anyone can reproduce?
Anyone got an idea to which team I should file a bug report? Silverlight team? IE team? VS Debugger team?
I'm able to reproduce this. You have handled the Click twice, once in XAML another time in code. See your MainPage.xaml
<Button x:Name="PrintButton"
Content="Gotta print 'em!" Margin="8"
Click="PrintButton_Click" />
Don't feel bad about it. I did it last time through a misplaced Print inside a loop.
I've also experienced this strange behaviour. A standard button click event immediately invoking an OpenFileDialog. It would frequently generate the same error when being debugged but would eventually be coaxed in to working when the button is clicked several times.
However when built as a release (or perhaps simply by running the same Xap without a debugger attached to the browser) the problem would go away.
Try to remove
if(SightPaleceListBox.Items.Count > 0)
I had the same problem and found out that the reason was this following line:
cnvsMain.Children.Remove(PrintPagePlaceHolder);
cnvMain is on the page that the user pushed the Print button on (I was trying to remove it from that page in order to add it to the canvas that I was going to print).
My tip: try to comment rows one by one, until you find what row causes the problem. Than try to work around it.

Debug assertion does not prompt in IIS 7

since moving to Windows 7 (IIS 7.5), the debug assertions do not prompt a pop up dialog anymore.
I have tested this in a separate project, and noticed that they do work when using the integrated Visual Studio Developer server (Cassini) but they do not work when using IIS Web Server.
This is a big issue for us since we are counting on debug assertions to identify potential programming errors, so any help would be appreciated.
Thanks. Eyal.
That's because failed debug assertions are displayed in the Output window now instead, under the Debug section.
To view the Output window in Visual Studio 2008 go to the 'View' menu and click 'Output'.
I also find it inconvenient. Some more info...
You can work around by using
System.Diagnostics.Debugger.Launch();
You can make for example this function
[Conditional("DEBUG")]
public static void AssertEx(bool condition, string message)
{
if (condition) return;
System.Diagnostics.Debugger.Launch();
// Still write the message on output
Debug.Fail(message);
}
and get similar results.
That is the default behavior now and it cannot be changed.
What you can is generate a file with the assertions that failed in your app. That will still help you track your issues without halting the app when running inside the IIS.
Take a look at this good article about it.

Resources