Reputation: 5107
I'm creating a DLL file in Visual Studio 2012 which is used as a class library plugin in a proprietary program.
The program loads the plugin DLL on startup and I can access it in a visual studio like fashion in the proprietary program.
But if a method in the plugin for some reason fails, I don't always get a stack trace and I can't single step through my source files.
I have placed my PDB files in the same directory but I believe the error handling of the environment takes over so I get an error that indicates where the proprietary program failed and not where my plugin failed.
I cannot create a test stub as the DLLs are dependent on instances created in the proprietary program.
How can I, in an efficient way, debug my DLL without having to put a message/log statement on every other line?
Upvotes: 2
Views: 1173
Reputation: 127543
Actually yea, it is really easy! All you need to do is add a event for AppDomain.FirstChanceException. Any execption that is thrown, even if they are in a try-catch block, will get passed off to this event.
public class MyPlugin : IPlugin
{
static MyPlugin()
{
AppDomain.CurrentDomain.FirstChanceException += FirstChanceHandler;
}
static void FirstChanceHandler(object source, FirstChanceExceptionEventArgs e)
{
MyErrorLogger.WriteLine("FirstChanceException event raised in {0}: {1}",
AppDomain.CurrentDomain.FriendlyName, e.Exception.Message);
}
}
Upvotes: 2
Reputation: 24515
Try placing the related .pdb file next to the .dll, that should make that information available.
Upvotes: 1