Debugging CRM .net API dlls

1 minute read time.

So you're having difficulty debugging a .net dll with Sage CRM, you have followed all the instructions in the documentation for setting up debugging but it still doesn't work... Microsoft only knows why sometimes the debugger just will not catch your breakpoints... Well here is a sure-fire way of getting a debugging environment to catch your code:

System.Diagnostics.Debugger.Break();

This will cause the operating system to look for a debugger for the currently executing process. You will get a window like this:

You can now choose which debug environment you want to use. If you already have the project open you can select it from here also.

Note that once the debugger has been attached any breakpoints you have set should work.

One way to make sure this works for all your pages is to put it in the App Factory constructor like this:

public static class AppFactory
{
static AppFactory()
{
#if (DEBUG)
System.Diagnostics.Debugger.Break();
#endif
...
Now every time CRM launches a page from your .net dll it will break on this line, giving you the opportunity to attach a debugger.
Parents
  • A small enhancement to the example above is to use an if statement to see if there is already a debugger attached and not break if there is... This saves you from hitting the same breakpoint every time you refresh the page after the debugger is attached.

    if (!System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Break();

Comment
  • A small enhancement to the example above is to use an if statement to see if there is already a debugger attached and not break if there is... This saves you from hitting the same breakpoint every time you refresh the page after the debugger is attached.

    if (!System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Break();

Children
No Data