Managed Debugging Assistants

Thursday, 11 June 2015

I was reading a copy of Jeffry Richter’s book CLR via C#today, and came across this note on p.538 “The .NET Framework offers a feature called Managed Debugging Assistants (MDAs). When an MDA is enabled, the .NET framework looks for certain common programmer errors and fires a corresponding MDA.”

What? I have I been living under a rock? Why hadn’t I heard of these before?

Well it turns out these have been around since .NET 2.0 (Visual Studio 2005), and you’ll find the list of available MDAs in the Exceptions dialog (Debug | Exceptions)

Visual Studio 2013 Exceptions Dialog

or in 2015 in the (new and improved non-modal) Exception Settings window (Debug | Exception Settings).

Visual Studio 2015 Exception Settings window

I must confess virtually the only time I visit this dialog/window is to expand Common Language Runtime Exceptions when I want to modify which exceptions the debugger automatically should Break When Thrown, so may be that’s why I’ve overlooked them.

The MDAs enabled by default in Visual Studio are:

  • CallbackOnCollectedDelegate
  • ContextSwitchDeadlock
  • DateTimeInvalidLocalFormat
  • DisconnectedContext
  • FatalExecutionEngineError
  • InvalidFunctionPointerInDelegate
  • InvalidMemberDeclaration
  • InvalidVariant
  • LoaderLock
  • NonComVisibleBaseClass
  • PInvokestackImbalance
  • RaceOnRCWCleanup
  • Reentrancy
  • You can also see the complete list and find out more about MDAs at Diagnosing Errors with Managed Debugging Assistants. MDAs are actually built in to the CLR and and as such aren’t user-extensible. Stephen Toub described them as “Asserts in the CLR and the base class libraries that can be turned on or off”.

    So while I don’t think I was consciously aware of them, it’s possible I have see the odd MDA exception dialog – but probably just didn’t noticed the difference from the usual exception dialog. Here’s an example of the BindingFailure MDA:

    BindingFailure Managed Debug Assistant dialog

    Bringing things full circle, it turns out that there’s a StreamWriterBufferedDataLost MDA which is what Jeffrey went on to highlight as a way to identify the problem where you’ve got a StreamWriter that didn’t get a chance to flush data to the stream before it was finalized (say because the underlying stream itself was already disposed).

    This MDA is not enabled by default, so it might be something worth doing if your code makes use of StreamWriters. Note: this is a debugging feature – it only works when you’re debugging an application. There may be other MDAs that you might benefit from enabling, depending on the kind of things your code is doing.

    In some ways, MDAs are a bit like a debugger-time version of FxCop (or FxCop’s probable replacement - the new Roslyn .NET Analyzers and Code Aware Libraries).

    Passed 70-494

    Thursday, 4 June 2015

    Back in April, I sat the Microsoft exam 70-494 Recertification for MCSD: Web Applications.

    And failed Sad smile

    And not by that much – 663 (the pass mark for Microsoft certification exams is always 700). So it’s hard to say, but it was probably around 2 – 4 incorrect questions.

    But fortunately Microsoft were running the “SecondShot” promotion until the end of May, so if you failed an exam you could try it again later for no extra cost.

    So today I re-sat the exam, and this time I passed (764 this time). Yay Smile

    I think this might be the first time I’ve done a recertification/update type exam. Because they are essentially combining what would otherwise be two separate exams (70-486 and 70-487) it does make it a bit more challenging as the breadth of subjects covered is essentially also doubled. Take a look at the Skills Measured section – there’s a fair bit there!

    You don’t get told which specific questions you got wrong, but I was able to recall a number of topics that came up in the first exam that I was unsure about so I took a bit of time to review those areas and become more familiar with them for the second time around. These were largely areas in which I don’t normally cover either for work or leisure. Of course there’s no guarantee that you’ll get the same questions – but it would be silly not to be prepared if something similar came up again.

    So now that’s done – it should keep the Microsoft Certified Solutions Developer: Web Applications certification active for another two years. It will be interesting to see what kind of skills they’ll be testing next time around.

    ANZ Coders Conference–10 unusual tips & tricks for .NET

    Thursday, 28 May 2015

    My second talk for the ANZ Coders virtual conference is now online. “10 unusual tips & tricks for .NET” manages to demonstrate 10 different tips in under 30 minutes.


    Source code for the demos is on Github. Over time, I hope to add to this repo as I come across new tips.
    If you prefer to see something in-person (and with pizza), then come along to the next Adelaide .NET User Group meeting on June 10th, when I’ll be doing an “extended play” version of this talk (and probably by then with a couple of extra tips thrown in to boot!). Register on MeetUp.

    ANZ Coders Conference–Hot Dates

    Tuesday, 26 May 2015

    My first talk at the ANZ Coders virtual conference titled “Hot Dates” is now online. In it I give an overview of some of the issues you need to deal with when working with dates and times in software.

    The resources I referred to at the end are:

    ANZ Coders

    Sunday, 3 May 2015

    If you haven’t heard, there’s a free virtual conference being run later this month – 24-29th of May to be exact. It’s called ANZ Coders.

    The format will be 3 sessions each evening. If you’re in Adelaide, it will be from 7.30pm – 9.30pm (or equivalent time elsewhere).

    Voting for which sessions are presented is now on (until May 10th).

    I’ve nominated a number of sessions – feel free to vote them up if you’d like to see one (or more) of them!

    There’s 28 proposals in total, but only 15 will get the nod (5 evenings x 3 sessions = 15!)

    Then go register and make time to check out the sessions in a few weeks when they’re presented live!