Thursday, 28 January 2016

Backwards compatible ignoring Roslyn Analyzer warnings

The “Roslyn” Analyzers are a great new feature that shipped in Visual Studio 2015. One nice thing about them, is you can still add them to a project even if the target platform for a project is not .NET 4.6. This makes sense, as the analyzers just run as part of the compiler – they don’t affect the generated code in any way.

This also means you can safely add analyzers to a project and get all the warnings/errors when using Visual Studio 2015, but you can still open the same project in an older version of Visual Studio and the analyzers are just ignored.

Sometimes you want to suppress a specific warning. It turns out there’s two ways to do this:

SuppressMessageAttribute

The first is the same that you would have done to suppress an old FxCop/Code Analysis violation – using the System.Diagnostics.CodeAnalysis.SuppressMessageAttribute attribute.

[SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]

It turns out, the only bit that Roslyn really cares about is the second parameter. As long as it starts with a valid CheckId, then that violation will be suppressed. My observation is that the first parameter (category) doesn’t seem to matter too much.

[SuppressMessageAttribute("StyleCop", "SA1514")]

Pragmas

The new compiler is much more flexible in disabling warnings and errors. You can now use a compiler pragma to disable a particular warning or error code – and the code isn’t just for the C# language, it can be for an analyzer too. eg.

#pragma warning disable SA1514

One advantage to using pragmas is that you can re-enable them if you want to limit the scope of the pragma to just a particular block of code in a single file.

Backwards-compatible pragmas

The only problem with the pragma approach above is if you try and compile the source code with the older non-Roslyn C# compilers. They haven’t ever heard of this ‘SA1514’ that you’re referring to and will generate a compiler error. The workaround is to wrap the pragmas with a conditional block, like this:

#if VS2015 

#pragma warning disable SA1514
#endif

The final part is to define ‘VS2015’. Do this by editing the .csproj file and adding the following block (insert it after the last configuration/platform-specific PropertyGroup)

<PropertyGroup>   
  <DefineConstants Condition="$(VisualStudioVersion) &gt;= 14 ">$(DefineConstants);VS2015</DefineConstants>
</PropertyGroup>

This has the effect of defining a conditional constant only when we’re compiling with Visual Studio 14 (aka 2015) or above. For earlier versions, the constant is undefined and so the pragma is not visible to the compiler.

Saturday, 23 January 2016

Time for a new laptop?

I thought it might be my imagination, but running powercfg.exe /batteryreport shows the truth – my laptop battery isn’t what it used to be.

Battery capacity history
PERIOD FULL CHARGE CAPACITY DESIGN CAPACITY
2015-11-17 - 2015-11-23 5,656 mWh 6,600 mWh
2015-11-23 - 2015-11-30 5,480 mWh 6,600 mWh
2015-11-30 - 2015-12-07 5,177 mWh 6,600 mWh
2015-12-07 - 2015-12-14 5,177 mWh 6,600 mWh
2015-12-14 - 2015-12-21 5,177 mWh 6,600 mWh
2015-12-21 - 2015-12-28 5,177 mWh 6,600 mWh
2015-12-28 - 2016-01-04 5,129 mWh 6,600 mWh
2016-01-04 - 2016-01-11 4,059 mWh 6,600 mWh
2016-01-12 3,276 mWh 6,600 mWh
2016-01-13 3,276 mWh 6,600 mWh
2016-01-14 3,276 mWh 6,600 mWh
2016-01-15 3,276 mWh 6,600 mWh
2016-01-16 3,276 mWh 6,600 mWh
2016-01-17 3,276 mWh 6,600 mWh
2016-01-18 3,276 mWh 6,600 mWh
2016-01-19 3,276 mWh 6,600 mWh
2016-01-20 3,276 mWh 6,600 mWh
2016-01-21 3,276 mWh 6,600 mWh
2016-01-22 3,276 mWh 6,600 mWh

This is not the original battery that came with my Dell XPS 1645. I originally had two 90mWh batteries, but both of those wore out. The current replacement was the only one I could find online (from a 3rd party – unfortunately Dell weren’t selling theirs anymore). I bought the 1645 back in 2010, so it will turn 6 in April – that’s not a bad effort for a laptop that has been lugged around a fair bit.

And so my mind now turns to thinking about getting a replacement laptop…

My initial specs are:

  • Gen 6 i7 or Xeon CPU
  • Minimum 16GB RAM (Prefer 16 would not be the maximum)
  • Minimum 512GB SSD (Ideally PCIe interface)
  • Decent screen resolution
  • Lighter than my 1645 (3.06KG/6.6lb according to the kitchen scales)
  • A bit smaller than the 1645 (380x260mm)

Possible options:

Let me know if you have any other suggestions or recommendations?

Friday, 15 January 2016

Upcoming Developer Events

There’s been a few announcements lately that will interest you if you’re a developer:

Know it. Prove it.

Microsoft Virtual Academy are running their “Know it. Prove it” challenge again during the month of February. It’s a chance for you to focus on learning something new in one of up to 10 ‘learning challenge’ areas. Register at the site to track your progress towards completing one (ore more) of the challenges and also earn some TechReward points (which you can redeem for actual stuff).

Executable Specifications in .NET with Storyteller 3

Next week JetBrains are hosting a webinar from Jeremy Miller on Storyteller, a tool for creating executable specifications in .NET. As well as creating Storyteller, you might also recognise Jeremy as the author of StructureMap. Register here to watch it live. Hopefully a recording will appear on the JetBrainsTV YouTube channel at a later date, as it turns out to be 1.30am in my time zone.

hack.summit()

Pluralsight are running hack.summit() a 4 day virtual developer conference, February 22-25. Speakers include well-known names such as Jon Skeet, Kent Beck, Joel Spolsky, Bob Martin and Yehuda katz. Register via the website – the cost is a donation to charity OR sharing the event on Twitter or Facebook.

DDD Melbourne 7

The date has been fixed for this year’s DDD Melbourne – Saturday, August 13th. That’s a week and a bit after NDC Sydney, if you were wondering. Speaking of Sydney, looks like they’ll also be hosting a DDD there sometime this year too (no date announced yet).

Saturday, 9 January 2016

Welcome to 2016 with Weird Al

I knew Weird Al Yankovic was touring Australia in January 2016, but when I jumped at the chance to see an NBA game during my visit to Toronto late last year I had resigned myself to the fact that doing so would probably mean passing on Al this time (I had seen him on his Poodle Hat tour back in 2003).

That was until Narelle spotted cheap tickets to Weird Al’s Adelaide concert appearing on lasttix.com.au. By clicking on the special (and avoiding signing up to lasttix because I didn’t want to if I didn’t have to), I ended up at ticketmaster, but with a cheaper price of just $60 per ticket instead of the usual $90+. Bargain!

There was a great crowd, a good supporting act in Mickey D (nice to have a comedian that was funny without being crude), and eventually Al and his band came on to give us a performance just like we were hoping.

Al with piano accordian playing a polka

Al doing Nirvana

The tech guy helping hold Al's harmonica

Word Crimes

More accordian

The Star Wars encore

It was a great mix of old favourites and songs from his latest album Mandatory Fun (which reached No. 1 on the Billboard charts recently)

All in all a great night out – even better as I went with friends Tom (whom originally introduced me to Al’s albums many years ago) and Derek (who wasn’t a huge Al fan before but I think enjoyed the night anyway).

Monday, 21 December 2015

Open Live Writer

I’ve been a fan of using Microsoft’s Windows Live Writer to compose blog posts for quite a few years now, so when it stopped working earlier this year due to Google changing the authentication requirements for Blogger, I was a bit disappointed. The good news was that Microsoft contacted Google and (for once) they extended Live Writer a lifeline to allow it to continue to use the old API until alternate arrangements could be made.

All was good just over a week ago, when a) Microsoft released an open source version of Live Writer – named Open Live Writer, and b) Google finally did switch off the old authentication API. Unfortunately the first new release of Open Live Writer didn’t have a working implementation of Google’s new authentication API, so there was a few days of inconvenience whilst that was finished off. Version 0.5.1.2 came out last Friday and I’m pleased to find that it does work again with Blogger!

The source code is on Github at https://github.com/OpenLiveWriter/OpenLiveWriter, and there’s already an active community contributing bug reports and pull requests.

It’s great to see such a useful application given a new lease on life (or should that be ‘new lease on live’ Smile )

Wednesday, 9 December 2015

Windows 10 Mobile on Lumia 920

(I wrote this post on 10th December, but was waiting for Open Live Writer to support Blogger)

So this happened.. Last week I reset my phone so that Narelle could use it for a day (hers had broken the previous day). Once I replaced hers and got my handset back, I reset it again and started re-installing all my apps. Windows Phone may not be the most popular phones around, but one of the nice things about them is that they do automatic backups, and by default save all your contacts to the cloud, so there isn’t much you can accidentally lose.

So after reinstalling everything I thought “hmm.. Maybe I should try out the Windows 10 update”. I’d resisted this urge previously as I’d read lots of reports of how unstable it was, but now the new 950/950XL handsets are out which come with Windows 10, and there’s just been an additional update since then too. Worst case I can use the support tool to reset my phone back to Windows Phone 8.1 again.

Phone Update screen installing Windows Phone 10Phone Update screen, install 10.0.10586.29

The install took a little while (maybe an hour?).

I did notice the battery seemed to run down a bit on the first day – admittedly that day included the update which would have used a bit of juice.

Windows Phone 10, Battery Status showing 23% left

The trouble is it’s hard to know if that is just Windows 10, or my handset – I’ve seen it occasionally do similar things with 8.1.

Windows 10 Mobile looks quite nice. The upgrade kept my icons on the start screen, though the layout needed tweaking as the size of the icons seemed to have changed slightly.

Windows Phone 10 Start Screen

Some of the apps are updated (eg. News, Mail, Calendar). Actually I think I prefer the 8.1 News app, but the new one is ok. I have two mail accounts on my phone, and they ended up being combined. Not sure if there’s a way to un-combine them.

Some pluses – they finally have an Australian keyboard option (Aussie! Aussie! Aussie! Oi! Oi! Oi!). The browser is also the latest Edge version.

Some minuses – possibly due to my older handset – I find the response time for various things quite slow. Even just turning the phone on and unlocking has a noticeable delay. The opposite is true of scrolling. It seems a bit too sensitive, and I often end up scrolling way further than I intended.

I’m going to stick with it for a little while and see how I go. If the battery does prove to be a problem then reverting back to 8.1 might be the best option.

Tuesday, 1 December 2015

Getting CA2213 warnings after installing Visual Studio 2015 Update 1

I installed Update 1 for Visual Studio 2015 this morning and then upon reopening an existing solution I noticed some new warnings/errors listed in the Error List panel:

Visual Studio Error List window showing CA2213 warning

The problem was that warning didn’t appear before the update, and inspecting the code revealed that in fact that class did implement IDisposable and did dispose the field in question. What’s going on here – surely this isn’t a bug in Update 1?

That was my original thought, but then I remembered that this project references the Microsoft.CodeAnalysis.FxCopAnalyzers Code Analyzer NuGet package. I wonder if that package needs an update?

Let’s fire up the NuGet Package Manager and make use of the new ‘Updates’ tab to find out..

NuGet Package Manager, showing 4 packages with updates

Yes, there are! A quick check of the Select all packages checkbox and click on the Update button, and tada – no more warnings Smile