visual studio doesnt catch ThreadAbortException - visual-studio

I've set up ThreadAbortException in the VS debug exceptions dialog, but it never breaks, even if I Thread.Abort() explicitly in my code.
I can see entries in the console such as:
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in System.dll
An exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll but was not handled in user code
Is there any way to get VS to break on these exceptions? (I'm using VS Express 2012 for desktop, but have access to the full VS if needed)

Redirect() calls End() which throws a ThreadAbortException exception upon completion. This is one source of such exceptions.
To break on exceptions select
Debug->Exceptions and for the Common Language Runtime Exceptions place a check in the Thrown column.
You can verify your settings are correct by running this sample code in a console application. The debugger should halt at the point where the thread is aborted.
using System.Threading;
using System.Threading.Tasks;
namespace AbortThread
{
class Program
{
static void Main( string[] args )
{
Task.Run( () => Thread.CurrentThread.Abort() );
}
}
}

Related

CDHtmlDialog OnInitDialog throws exception when loaded in context of CredentialUIBroker.exe

My credentialprovider has a CDHtmlDialog which throws an exception only when the credprov dll is loaded by credentialuibroker.exe (the UAC like prompt with the title Windows Security, when you do remote or access a network folder).The credential provider displays the CDHtmlDialog successfully during Windows logon (logonui.exe) or accessing a network resource (explorer.exe).
Note that the exception is inside MFC's implementation of CDHtmlDialog.
File - dlgdhtml.cpp.
BOOL CDHtmlDialog::OnInitDialog()
{......
m_wndBrowser.CreateControl(CLSID_WebBrowser, NULL, WS_VISIBLE | WS_CHILD, rectClient, this, AFX_IDC_BROWSER);
lpUnk = m_wndBrowser.GetControlUnknown();
// The next line throws exception that - Unhandled exception at 0x6be243d8 (mfc100.dll) in CredentialUIBroker.exe: 0xC000041D: An unhandled exception was encountered during a user callback.
if (FAILED(lpUnk->QueryInterface(IID_IWebBrowser2, (void**) &m_pBrowserApp)))
{......
}
}
I have tried with same results, the sample credential provider available in MS SDK. I have tried Visual Studio 2010 and Visual Studio 2015. I have tried adding CoInitialize, AfxOleInit to InitInstance.
Let me know if anybody has suggestions on what could be wrong.
Thank you

How to intercept and handle all exception of Windows phone Application?

We did't have any Test team support for our Product Development.
so.
we need intercept and handle all Exception for improve User experience.
is There have any Soluction in windows phone Application?
as Fllow in app.xaml.cs file. we found :
// Code to execute on Unhandled Exceptions
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (e.ExceptionObject is QuitException)
return;
if (System.Diagnostics.Debugger.IsAttached)
{
// An unhandled exception has occurred; break into the debugger
System.Diagnostics.Debugger.Break();
}
if (System.Diagnostics.Debugger.IsAttached)
{
// An unhandled exception has occurred; break into the debugger
System.Diagnostics.Debugger.Break();
}
}
Yes, this should catch all the exceptions that you missed in your app. Considering that you obviously are not catching many exception somewhere else and are looking for a simple solution, this event handler might work, but I seriously don't recommend it.
This event handler catches the exceptions and then should crash/quit your app. If you handled your exceptions only here, this would lead to a huge crash count. Sometimes exceptions happen, but the app can continue working normally. That's why I recommend that you handle them as they happen in your code, and not here. That way you have a full control of how your app continues and if it continues at all, and reduce the number of "unhandled exceptions" and app crashes.
Put your code in Try-Catch Block. I was also facing such problem, but then handled by Exception Handling Method.
try
{
// your code
}
catch (Exception ex)
{
throw (ex);
}

Why is DbgView missing some trace writes, but the traces can be seen in test runners

Can anyone explain why DbgView misses some of my trace writes ?
I'm using the Enterprise Library 5.0 logging block with a trace listener deriving from the EntLib CustomTraceListener, as below ...
[ConfigurationElementType(typeof(CustomTraceListenerData))]
public class DebugTraceListener : CustomTraceListener
{
public override void Write(string message)
{
Debug.Write(message);
}
public override void WriteLine(string message)
{
Debug.WriteLine(message);
}
public override void TraceData(TraceEventCache eventCache, string source,
TraceEventType eventType, int id, object data)
{
if (data is LogEntry && Formatter != null)
{
WriteLine(Formatter.Format(data as LogEntry));
}
else
{
WriteLine(data.ToString());
}
}
}
I can see all the trace in both the Resharper test runner in VS2010, and in the NUnit GUI tester.
I can also send the trace to a flat file listener and this captures all the trace writes,
BUT when I use DbgView (and also TraceSpy) only some of the trace is being shown.
The other wrinkle is I'm using PostSharp to add the logging as an aspect, via attribute, rather than directly in the business code
I've seen this happen when you have another application running that is also capturing some part of the debug traffic. If you're running an application and have VS2010 debugging some component you won't see whatever debug output is being routed to the IDE instead of DebugView. This can be handy if you're testing client-server applications on the same box at the same time but can cause the issue you describe. Short of that I'd just make sure that Capture Global Win32 is checked from the Capture menu as well (I've seen that make a difference even when I wouldn't have expected it to).
Are the missing messages always the same ones?

PROBLEM :An error message cannot be displayed because an optional resource assembly containing it cannot be found

I created Windows Mobile Application and I loaded web service that contain one method (GetNumber). When I call this method from my emulator I got a following exception
An error message cannot be displayed because an optional resource assembly containing it cannot be found.
Can anyone help me. This is my code from WM Application, it is very siple.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MobileClientApp;
namespace MobileClientApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MobileClientApp.localhost.WebService m = new MobileClientApp.localhost.WebService();
int result;
bool resbool;
m.GetNumber(10, true, out result, out resbool);
label1.Text = result.ToString();
}
}
}
For a very good explanation:
http://blogs.msdn.com/b/netcfteam/archive/2004/08/06/210232.aspx
(excerpt from above)
There has been some confusion about the error message: "Could not find resource assembly". Basically, this means that there is some exception that has happened in the program. The error did not happen because it could not find the resource assembly. The resource assembly that it is searching for contains exception messages (strings) that would be helpful in debugging what went wrong with the program.
Since the user is never expected to see this error message if the program works as expected and all exceptions are handled appropriately, it was decided (due to size constraints) that the resource assembly that has these error strings are never put on a user's device. Thus the main target audience of these error strings are developers who would like to debug issues. Hence, when you do an F5 deploy onto the device, the System.SR.dll assembly which have these error strings are copied to the device and the developer can see the error messages. But in case .Net Compact Framework is installed from a redistributable or you are using .Net Compact Framework that come with the device (as a user of the device would be doing), the System.SR.dll is not present on the device. Hence, if the application did come upon an exceptional condition that wasn't handled by the application, this "Could not find resource assembly" message would be shown to the user.
If you are not using Visual Studio F5 deploy to the device and would still like to see the exception messages, you can achieve this by taking the System_SR_[Language].CAB where [Language] corresponds to the language in which you want to see the error message to appear and clicking on the cab file to install it
Sounds like you are missing an assembly in your deployment.

Debugging an exception in an empty catch block

I'm debugging a production application that has a rash of empty catch blocks sigh:
try {*SOME CODE*}
catch{}
Is there a way of seeing what the exception is when the debugger hits the catch in the IDE?
In VS, if you look in the Locals area of your IDE while inside the catch block, you will have something to the effect of $EXCEPTION which will have all of the information for the exception that was just caught.
In Visual Studio - Debug -> Exceptions -> Check the box by "Common Language Runtime Exceptions" in the Thrown Column
You can write
catch (Exception ex) { }
Then when an exception is thrown and caught here, you can inspect ex.
No it is impossible, because that code block says "I don't care about the exception". You could do a global find and replace with the following code to see the exception.
catch {}
with the following
catch (Exception exc) {
#IF DEBUG
object o = exc;
#ENDIF
}
What this will do is keep your current do nothing catch for Production code, but when running in DEBUG it will allow you to set break points on object o.
If you're using Visual Studio, there's the option to break whenever an exception is thrown, regardless of whether it's unhandled or not. When the exception is thrown, the exception helper (maybe only VS 2005 and later) will tell you what kind of exception it is.
Hit Ctrl+Alt+E to bring up the exception options dialog and turn this on.
Can't you just add an Exception at that point and inspect it?
#sectrean
That doesn't work because the compiler ignores the Exception ex value if there is nothing using it.

Resources