Monday 6 May 2013

How to use Microsoft.Bcl.Async correctly on XP

We recently updated our Terminator for Windows Desktop application to use the async/await features and still target .NET 4.0 so our XP customers can continue running the program.

So, first we updated our copy of Visual Studio 2012 to the latest and greatest release 2, and installed NuGet too.  So far so good.

Our installer is based on WiX, so we also updated to version 3.7, but we built our own bootstrapper, so we ported that to VS 2012.

Unfortunately, that led us to discover that a regression causes VS2012 Rel 2 to produce programs that don’t actually run on XP, as described here on connect, but luckily there’s a solution that works on the workaround page

That’s the first hurdle down.  So, we then added support for Microsoft.Bcl.Async by typing into the NuGet Package Manager Console:

Install-Package Microsoft.Bcl.Async

From there we could target.net and declare async entry points and await them to our hearts content.

So it came time to obfuscate.  We use EazFUSCATOR.net, which lets you trial for free for 30 days.  We’ve found it well worth the investment to purchase this package, which also gives support.  Unfortunately, VS2012 and Microsoft.Bcl.Async broke Eazfuscator 3.7, but the team there pulled out all of the stops and got us a beta that fixed the problems we’ve had within 24 hours of each problem.

So, we were good to go.  We tested it all and everything seemed hunky dory.  The only thing was, we started to notice that the async routines seemed to be very async.

how ASYNC?

Well, so async that they never, ever completed.  This was a bit of a puzzle.  It appeared that the methods were never completing at all.  So what went wrong?

It turns out that you must actually install some new DLL’s when you install your package, or it will just fail silently (which was the real surprise).

  • Microsoft.Threading.Tasks.dll
  • Microsoft.Threading.Tasks.Extensions.Desktop.dll
  • Microsoft.Threading.Tasks.Extensions.dll
  • System.Runtime.dll
  • System.Threading.Tasks.dll

Needless to say, we’d forgotten to add these into our WiX installer, and as a result the machines that were using the installer were failing to fetch the cloud overlay, until we added them.

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. And there are a few more issues, it turns out.

    First, we also needed to ship the app.config for the program, which also was copied to our output directory, and you also need to make sure that .NET 4.0 has had updates applied to it, particularly this gem:

    Using Microsoft.Bcl.Async on .NET 4 requires http://support.microsoft.com/kb/2468871 to be installed.

    from here: http://blogs.msdn.com/b/bclteam/p/asynctargetingpackkb.aspx

    ReplyDelete
  3. Thanks for sharing your experience, it saved me from a lot of headache! Sadly, i can't ask to our customers to install another package only for using async so i'm not using those great libraries :( Thank you again!

    ReplyDelete