When debugging an application in Visual Studio, there are 2 options for breaking on exceptions. Break as soon as an exception is thrown, and breaking only when an exception isn't caught. This works fine when developing desktop applications. However, when developing ASP.NET applications, all exceptions are eventually caught by the code in IIS. Is it possible to disable this behavior, so that the debugger breaks when my ASP.Net application code fails to catch an exception?
Edit:
Just to be clear, I don't want to break whenever an exception is thrown, as many times they are handled just fine by my code, and I don't want to stop on every exception. I only want to stop on the exceptions that aren't handled by my code.
Edit:
This seems to not be an issue in Visual Studio 2008. In Visual Studio 2003, all exceptions were treated as user handled, because the ASP.NET runtime caught all the exceptions so as not to bring down the web server process. It seems that in Visual Studio 2008, this type of exception catching is not counted when checking for user-unhandled exceptions.
Under Debug->Exceptions, check the 'Thrown' column of Common Language Runtime Exceptions (at a minimum). Check 'Thrown' for other Exceptions you're interested in.
Now, if the debugger is attached (active debug or 'Attach to Process'), your ASP.NET app will break on a CLR Exception (or any other Exception you've selected).
[EDIT]
If you want to break only on unhandled Exceptions, under Debug->Exceptions, uncheck 'Thrown' on all Exception types and make sure 'User-unhandled' is checked for the Exceptions you're interested in.
Then, if the debugger is attached, your ASP.NET app will break on every User-unhandled Exception you've selected regardless of the fact the runtime will eventually catch the Exception. Sample:
Related
I have a simple Winforms application.
I've added a ChromiumWebBrowser control on my Form and I'm navigating on various pages.
For unknown reasons, an exception is thrown from Chromium which causes my app to crash
CefSharp.BrowserSubprocess.exe Description: The process was terminated
due to an unhandled exception.)
Is there a way for me to somehow handle that error so my app doesn't crash?
(and maybe reload the current page)
I am working with a ASP.NET 4.0 web application that has a pre-compiled portion, along with user controls that represent individual modules (think CMS). Running VS 2015 or 2013. On Windows 8.1, if my user control failed to build at run-time my development environment would exhibit typical behavior, which is a build exception, VS would break, give me the line number, I would fix the problem and move on, the application would continue to run.
Under Windows 10 the application runs ok. But if I have a build error, anything as simple as a typo in a control ID name, I get a 'System.Threading.ThreadAbortException' in unknown module, with no additional information. Application stops running. Any thoughts?
Setting and hitting a breakpoint also causes this behavior.
I am receiving the following error message:
Server Error in '/' Application.
Security Exception
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException: System.Security.Permissions.SecurityPermission
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SecurityException: System.Security.Permissions.SecurityPermission]
MySql.Data.MySqlClient.MySqlClientFactory..cctor() +23
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
MySQL: mysql-connector-net-6.7.4
The problem only occurs if run from the shared web hosting environment. The site works great locally. I know the version of the .Net connector that my shared hosting environment uses, as that was another issue that I resolved and I was in communication with the hosting provider.
The error is interesting. I can go to the default page, no issues, the very first time. I then go to bring up a popup dialog, which throws another error message box.
Exception has been thrown by the target of an invocation.
The above is everything, except for the okay button.
I can bring up the first popup, a sign in dialog, which comes up. That dialog does not invoke MySQL. I bring up the second dialog, a registration dialog, which then throws the "Exception has been thrown..." message box. After that, I cannot go back into the sign-in dialog, as I get the "Exception has..." message box. If I press F5 to refresh the browser (IE or Chrome), I get the error from above. The above error indicates MySQL and some permissions.
I am suspecting that the "Exception has been thrown..." error is the result of the same MySQL, just the page has memory. Closing the browser window and launching the browser window again does not help, although on Chrome that works, just the browser window there really has to close down all the way.
I am in a shared hosting environment, so I have access to basically nothing, so I do not have access to any logs, at least that I can think of.
One final thought that may or may not be relevant. Yesterday and previous days my development work was done on a system with Windows 7 Professional and Visual Studio 2012 Professional (all latest service packs and updates), whereas today I am working at a different computer of mine, which is a system with Windows 8 Professional and Visual Studio 2012 Ultimate (all latest service packs and updates on the OS and VS). I was reading some other posts on unrelated issues that people with VS2012 Ultimate had issues, so I am not sure that has anything to do with it, but that is something that changed from yesterday to today.
Yes, I deleted everything off of the server and uploaded everything anew. I did a clean solution first, built the release, and then published. I still received the same error.
Any thoughts?
By default most hosts use "Medium" trust level. You can change your web.config as below to get full trust:
<configuration>
<system.web>
<trust level="Full" />
</system.web>
</configuration>
At our shop, we develop on Windows Server 2008 VMs running IIS 7, same as our production web servers. With VS2010 (and VS2008, but more so 2010), I've been having issues with debugging our ASP.NET applications. If the application throws an exception, I'll often kill the debugger (Shift-F5) so I can correct the faulty code. But after doing this, the process in IIS continues running, with the exception!
This leads to numerous faulty scenarios. Sometimes the exception floats to the top at IIS, and I get a prompt asking "Would you like to debug this process in [choice of Visual Studios]" and other times there is no prompt but the debugger reattaches to the faulty process instead of starting a new one the next time I go to debug.
What am I doing wrong here? Or what is configured wrong? I want the workflow I had back: run web site, see exception, fix code, run web site again to verify fix. Instead I have to manually kill W3WP in the task manager in order to continue working.
Extra info: It may also be related to the fact that the solution contains both a web site application and a web service application which the site application accesses, both running on the local IIS in two virtual directories. Normally the attached debugger will drop into either the web site or service, if either has a problem.
I wonder if there's something else going on that is being hidden. Can you setup Visual Studio to break on all exceptions. From with in the IDE press CTRL + ALT + E. That will open the Exceptions dialog.
By default, the IDE will only break on user-unhandled exceptions. If a different exception is being thrown you might not know about it. Add checks to each checkbox in the "Thrown" column and try running through your code another time. If another exception is being generated, Visual Studio will break on it now.
I develop and debug an ASP.NET application with VS 2010. My ASP.NET application holds some connections to other applications on other machines. When I stop debugging, I want these connections to be released. If this doesn't happen, these other applications fail and I have to restart them.
In the end I will store my termination code in the Application_End method in Global.asax.cs, but this one is not called when stopping debugging.
Is there a way to terminate the debugging of my ASP.NET application so that not everything is killed at once, but so that one last method is called in which I could add my termination code?
I'm not sure what your problem is but probably...
You initialize your debug session by pressing F5 and thus debugging through cassini. This way when you end your debug session the application is terminated.
If you have a configured IIS application you could simply attach to the running process - it's usually "CTRL + ALT + P" - choosing w3wp.exe (mind the checkboxes on the bottom to be checked). This way your app won't be terminated on ending the debugging session.
Does it solve your problem?
I misunderstood how debugging an ASP.NET application works. I thought the moment I stop debugging (by pressing Shift+F5) the ASP.NET application is terminated and no further line of code is executed. It was my explanation to why the Application_End method is not called.
But in fact the ASP.NET application goes on when the debugger is detached and therefore the Application_End method is not called.