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 (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.
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.
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.
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:
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.
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!
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) or in 2015 in the (new and improved non-modal) Exception Settings window (Debug Exception Settings).
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:
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:
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).