Saturday, 20 June 2015

Speaking at DDD Melbourne 6

I’m excited to confirm that I’ve had a talk accepted for DDD Melbourne, a one day developer conference to be held on Saturday 8th August, in yes, Melbourne Smile(flights are booked!)

My “10+ unusual tips & tricks for .NET” presentation (previously featured online and at last week’s ADNUG meeting) is listed as one of the last sessions of the day before the closing locknote. ADNUG attendees will be able to confirm that I do indeed have more than 10 tips.

The agenda is now live - http://dddmelbourne.com/agenda

If you’d like to attend, you’ll want to set an alarm for 29th June at 12:30+0900 – as that’s when tickets go on sale. Last year they sold out in just 12 hours, so I wouldn’t be surprised if they go even quicker this time.

It should be a great event, and I’m really looking forward to being a (small) part of it.

Monday, 15 June 2015

Finding missing files in Visual Studio

A project in Visual Studio is used to indicate which files on disk should be used to build something. For a C# project, it will indicate the .cs files that should be compiled.

It is possible to have a file on disk that isn’t included in the project (the file is just ignored), and conversely it is possible to have a file reference in the project that refers to a file that doesn’t exist on disk. In this latter scenario, if it is a compilable (.cs) file then the C# compiler will issue an error that it can’t find the file. But if it is another kind of file (like a .jpg, .png or .css for example), the compiler just ignores it and you won’t get any errors.

If you didn’t realise that there are some missing files, then the first time you might actually realise this is when either you go to package the application for deployment (when the packaging step could fail), or when you run the application and some functionality is broken.

Here’s a Solution opened in Visual Studio. I can tell you there are actually two files that are missing, but there’s no clue as to where they might be.

Visual Studio Solution Explorer, with projects collapsed

Missing files are identified by a slightly different icon with a yellow ‘warning’ triangle in the Solution Explorer, but that’s only helpful if you’re actually looking at the right place (not always easy if you have lots of projects with a deep folder hierarchy). If we expand the first folder out, then we can see the first missing file.

Visual Studio Solution Explorer, with first project expanded

But there’s still another one we haven’t found. If you don’t go looking for it, you probably won’t notice it. So to help identify missing files as soon as possible, I’ve created a new Visual Studio extension – Show Missing Files.

After you do a build, the extension scans all the projects you have loaded in Visual Studio and generates errors for any files that are referenced but don’t actually exist. Here’s the Error List window for our sample solution after doing a build:

Visual Studio Error List, with two missing file errors

The two missing files are listed, along with the projects that reference them. You can then double-click on one of the errors and it will take you directly to the file reference in the Solution Explorer.

Visual Studio Solution Explorer with second missing file highlighted

And there it is! You can now fix the missing reference (eg. remove it, or restore the missing file back on disk).

Show Missing Files is available for Visual Studio 2013 and 2015. Try it out today in the Visual Studio Gallery or search for “Show Missing Files” in the Visual Studio Extensions and Updates dialog.

Don’t forget to give it a few votes in the gallery. The source code is available at https://github.com/flcdrg/VsShowMissing. All contributions welcome!

Thursday, 11 June 2015

Managed Debugging Assistants

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).

    Thursday, 4 June 2015

    Passed 70-494

    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.

    Thursday, 28 May 2015

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

    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.

    Tuesday, 26 May 2015

    ANZ Coders Conference–Hot Dates

    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:

    Sunday, 3 May 2015

    ANZ Coders

    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!