Scott Hanselman

Getting ready for the future with the Microsoft .NET Portability Analyzer

December 3, '14 Comments [13] Posted in Learning .NET
Sponsored By

.NET has been getting more and more portable. Not only is .NET Open Source going forward (read Announcing .NET 2015 - .NET as Open Source, .NET on Mac and Linux, and Visual Studio Community) but you of course know about Xamarin tools, as well as, I hope, the .NET Microframework, and much more.

You can run your .NET code all over, and there's a tool to make this even easier. While you'll rarely get 100% portable code with any platform, you can get into the magic 90-95% with smart refactoring, then keep the platform-specific shims pluggable.

The .NET Portability Analyzer is a free Visual Studio Add-in (or console app) that will give you a detailed report on how portable your code is. Then you can get a real sense of how far you can take your code, as well as how prepared you'll be for the Core CLR and alternate platforms.

.NET Portability

Take a look at this report on AutoFac, for example. You can see that the main assembly is in fantastic shape across most platforms. Understandably the more platform-specific Configuration assembly fares worse, but still there's a complete list of what methods are available on what platforms, and a clear way forward.

.NET Portability Report

You'll get suggestions with a direction to head when you bump up against a missing or not-recommended API.


You can analyze specific assemblies, or an entire project. Once installed, you'll find the commands under the Analyze menu, and you can change options in the .NET Portability Analyzer options in the Tools | Options menu.

Even better, you can use this with the FREE Visual Studio Community that you can download at

Related Links

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web

Building a working Robot controlled by a C#, an iPhone, and Monkey.Robotics

October 28, '14 Comments [24] Posted in Learning .NET | Open Source
Sponsored By

Robot_TinyThis year at Xamarin's Evolve there was a Robot Building area that introduced a new beta platform called Monkey.Robotics (GitHub). There is a disclaimer on the GitHub: "Monkey.Robotics is still a beta/work in progress and is not officially supported by Xamarin" but I can say that I was able to successfully build this robot with my 6 year old and we've had a blast driving it around the house! He was thrilled to solder (but not too much) and setup all the wires on the breadboard.

This robot is a great showcase for the larger Monkey.Robotics stack PLUS a great way to learn how to use Xamarin tools AND the .NET Micro Framework. And the end you'll have not just a robot with code running on a Netduino, but also have deployed C# code using Xamarin onto (in my case) an iPhone.

The resulting stuff you get to build and use are:

  • iPhone/Android app using Xamarin.Forms and controls or a gyroscope talking over your phone's Bluetooth radio to some code running on an...
  • Netduino running the open source .NET Micro Framework. This Netduino will receive communications via a Bluetooth radio on a chip. This BT LE board is connected to the GPIO (general purpose input output) pins on the Netduino. The board then controls...
  • Motors and wheels on a nice base, powered by 4 AA batteries.

The authors are some of my favorite people, including Bryan Costanich, Frank Krueger, Craig Dunn, David Karlas, and Oleg Rakhmatulin.

There's a deceptively large amount of code here and it's whole job is to hide the yucky parts of a project that connects mobile devices to wearables, sensors, peripherals, and low-level communication. They include a cross-platform API for talking with BLE (Bluetooth Low-Energy) devices, as well as the beginnings of a similar API over Wifi. Even more important is a higher level messaging framework sitting on top of these lower=level APIs. The net result is that talking Bluetooth between your phone and a device isn't very hard.

On the device side (in my case with .NET Micro Framework) they make things more compose-able with "blocks and scopes" style abstractions, allowing one to fairly easily connect output pins (LEDs, motors) to input pins (buttons, sensors).

Here is one of their basic examples. This makes an LED blink when a button is pressed.

public class Program
static H.Cpu.Pin buttonHardware = Pins.ONBOARD_BTN;
static H.Cpu.Pin ledHardware = Pins.ONBOARD_LED;

public static void Main()
var button = new DigitalInputPin (buttonHardware);
var led = new DigitalOutputPin (ledHardware);

button.Output.ConnectTo (led.Input);

// keep the program alive
while (true) {
System.Threading.Thread.Sleep (1000);

I went through the very excellent Project Walkthrough on building a Robot. Note that all this is on GitHub so if you have any issues, you can fix them and submit a pull request. I'm sure the project would appreciate it!


Here's what you need to buy/or have (I took from their GitHub site) if you want to build this same robot.

  • bot Chassis w/Motors - Just about any 2 wheeled robot chassis with motors and gears will work, but we like these. They're only $11 and they work well. Spark Fun also makes a similar robot chassis for $15, but the battery holder is difficult to access, otherwise, it's also very nice.
  • Netduino 2 - From Secret Labs, the Netduino is a programmable micro controller that runs the .NET Micro Framework.
  • BLE Mini - From Redbear Labs. Used to communicate with the robot from Xamarin.iOS and Xamarin.Android.
  • 400 Point Breadboard - The breadboard is where our electronics will all get connected. It has holes in it to put chips, sensors, wires, etc., into.
  • Breadboard Wiring Kit - Any wiring kit will work, but we especially like these. You may also want to get some male-to-male flexible jumper wires.
  • Dual H-Bridge Chip - Used to power the motors, H-bridges are simple chips that allow you to control motors with external power, so you don't burn out your Netduino trying to drive them with that. :) You can also build an H-bridge with some simple components, but buying a chip is easier and will likely cost about the same.
  • iOS or Android Device w/BLE Support - If using an iOS device, you'll need an iPhone 4 or later. If using an Android Device, you'll want to make sure that it has BLE support and is running at least Android v4.3.

Make sure you have you development and build environment setup, and then follow the guides below to get this thing up and running!

Basically you'll need Xamarin Studio or Visual Studio with Xamarin Tools. You'll also need the .NET Micro Framework bits, which are free for Visual Studio 2013, as well as the Netduino 4.3.1 SDK. There's a thread over at the Netduino Forums if you have trouble getting your device ready. I had no issues at all.

The Robot code is in a larger solution called Robotroller that's pretty nicely factored. You've got the Core functionality for the phone and the Core for the Robot.

The Phone code makes great use of databinding. The Car code is a little messy (it's beta and looks like Tests that turned into a working Robot! ) but it worked out of the box! It's surprisingly simple, in fact, due to the next abstraction layer provided by Monkey.Robotics.

How cool is this. That's basically it. Love it.

public class TestRCCar
public static void Run ()
// initialize the serial port for COM1 (using D0 & D1)
// initialize the serial port for COM3 (using D7 & D8)
var serialPort = new SerialPort (SerialPorts.COM3, 57600, Parity.None, 8, StopBits.One);
serialPort.Open ();
var server = new ControlServer (serialPort);

// Just some diagnostic stuff
var uptimeVar = server.RegisterVariable ("Uptime (s)", 0);

var lv = false;
var led = new Microsoft.SPOT.Hardware.OutputPort (Pins.ONBOARD_LED, lv);

// Make the robot
var leftMotor = HBridgeMotor.CreateForNetduino (PWMChannels.PWM_PIN_D3, Pins.GPIO_PIN_D1, Pins.GPIO_PIN_D2);
var rightMotor = HBridgeMotor.CreateForNetduino (PWMChannels.PWM_PIN_D6, Pins.GPIO_PIN_D4, Pins.GPIO_PIN_D5);

var robot = new TwoWheeledRobot (leftMotor, rightMotor);

// Expose some variables to control it
robot.SpeedInput.ConnectTo (server, writeable: true, name: "Speed");
robot.DirectionInput.ConnectTo (server, writeable: true, name: "Turn");

leftMotor.SpeedInput.ConnectTo (server);
rightMotor.SpeedInput.ConnectTo (server);

// Show diagnostics
for (var i = 0; true; i++) {
uptimeVar.Value = i;

led.Write (lv);
lv = !lv;
Thread.Sleep (1000);

Here's a video (don't play it too loud, my kids are yelling in the background) of me controlling the robot using my iPhone. Note I'm using the gyroscope control so I twist my hand to steer.

Robot via iPhone over BT LE. It's @Xamarin on phone plus @SecretLabs and @Xamarin on robot!

A video posted by Scott Hanselman (@shanselman) on

All in all, I'm enjoying Monkey.Robotics and I hope it takes off with more projects, more ideas, more things to build. If you've got interest or expertise in this area, go star their project and get involved! There's a LOT of stuff going on over there, so explore all the docs and diagrams.

Sponsor: Big thanks to my friends at Octopus Deploy. They are the deployment secret that everyone is talking about. Using NuGet and powerful conventions, Octopus Deploy makes it easy to automate releases of ASP.NET applications and Windows Services. Say goodbye to remote desktop and start automating today!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web

Catch up on all the videos from DotNetConf Spring 2014

July 3, '14 Comments [10] Posted in Learning .NET
Sponsored By

Did you miss out on DotNetConf when it streamed LIVE just a few weeks ago? Don't you worry, it's all recorded and online for you to stream or download!

We are happy happy to announce that we’re planning another .NET Conf to be happening in a few months, so keep tuned thru the .NET Conf Twitter account (Twitter: @dnetconf), or checking our .NET Conf site in the future: Big thanks to Javier Lozano for all his work with the site and conference coordination.

Everything was recorded is is up here:

.NET Conf summary and recorded content

The .NET Conf 2014 was a two-day virtual event (June 25th-26th) focused on .NET technologies, covering application development for the desktop, mobile and cloud/server. It is hosted by the MVP community and Microsoft, bringing top speakers and great topics straight to your PC.

Below you can review all the delivered sessions and reach to their related recorded content.

Day 1 – .NET core and .NET in client/devices

clip_image001 State of .NET (Keynote) - Jay Schmelzer
Opening and overview of current .NET state and .NET on the Client side.


New Innovations in .NET Runtime

Andrew Pardoe

We're changing the way we execute code in the .NET Runtime. Hear about .NET Native, RyuJIT, and modern server strategy.


The Future of C#

Kevin Pilch-Bisson, Mads Torgersen

The Microsoft Managed Languages team has been focused on rebuilding the VB and C# compilers and editing experiences as part of Project "Roslyn". This effort has paved the way for these languages to continue evolving for many years to come. However, what does that future actually look like? We explore the editing experience, how public APIs may be used to write language-level extensions, as well as new language features.


Building Universal Windows Apps with XAML and C# in Visual Studio

Larry Lieberman

In April at Build 2014, Microsoft unveiled universal Windows apps, a new approach that enables developers to maximize their ability to deliver outstanding application experiences across Windows PCs, laptops, tablets, and Windows Phones. This means it's now easier than ever to create apps that share most of their code. Code can be shared using the new shared app templates, as well as by creating Portable class libraries. This session will walk through the development of a shared app and will discuss where it still makes sense to implement platform specific features.


.NET Native Deep Dive

Andrew Pardoe

Look inside the .NET Native compiler toolchain to understand how we enable .NET Windows Store apps to compile to self-contained native apps.


Fun with .NET - Windows Phone, LEGO Mindstorms, and Azure

Dan Fernandez

In this demo-packed session, we'll walk through building your first .NET controlled LEGO Mindstorm using Windows Phone. You'll learn about the LEGO EV3 API, how to control motors and read sensor data, and how to batch commands to the robot. Once we have a working, drivable robot, we'll switch to cloud-enabling the robot so that you can drive the robot remotely via a Web site hosted in Microsoft Azure.


Kinect for Windows

Ben Lower

We will take a look at what's new in Kinect for Windows v2 including the improvements in core sources like Infrared and Depth data.  We will also show how the new Kinect Studio enables Kinect development even while travelling via plane, train, or automobile (note: you should not dev and drive) and how Kinect Interactions can be used to add a new input modality to Windows Store applications.


What's New in XAML Platform & Tooling

Tim Heuer

Tim will do a lap around what is new to the Windows Phone 8.1 platform as well as a tour of the new XAML tooling in Visual Studio Update 2 for developers and designers.


Developing Native iOS, Android, and Windows Apps with Xamarin

James Montemagmo (Xamarin)

Mobile continues to expand and evolve at a rapid pace. Users expect great native experiences in the palm of their hands on each and every platform. A major hurdle for developers today is that each platform has its own programming language and tools to learn and maintain. Even if you tackle the burden of learning Objective-C and Java you will still have to manage multiple code bases, which can be a nightmare for any development team large or small. It doesn't have to be this way as you can create Android, iOS, Windows Phone, and Windows Store apps leveraging the .NET framework and everything you love about C#.


What's new for WPF Developers

Dmitry Lyalin

Windows Presentation Foundation (WPF) enables .NET developers to build rich and powerful Windows desktop applications using managed languages and XAML. In this session we'll cover all the latest innovations available to WPF developers such as improvements coming from .NET, integration points with the latest cloud technologies and enhanced tooling & profiling capabilities in Visual Studio.

Day 2 – .NET in server and cloud


ASP.NET Today and Tomorrow (Keynote)

Scott Hunter

It's been an amazing decade for ASP.NET. Today in 2014, most all of ASP.NET is open source, developed in the open, and accepting community contributions. One ASP.NET and VS 2013 added some amazing new tooling enhancements for HTML5, CSS3 and JavaScript. VS2013.3 is coming soon with even more innovations as we march towards ASP.NET vNext. Join Scott Hunter as he shows you how it works together. What's available on ASP.NET today, and where is ASP.NET headed tomorrow, and what do you need to know to best support the code you've written and the code you will write. We'll also talk about the rise of the cloud and how it changes the way we write large systems. All this, plus a lot of open source, and deploying to Azure.


ASP.NET Web Forms

Scott Hunter, Pranav Rastogi

Do you want to learn techniques to enhance your Web Forms development experience. See how you can improve your code's maintainability and testability and your site's performance. Leverage new features in ASP.NET Web Forms 4.5 to reduce the amount of UI "yuck" code and focus on your application's logic. We will look at some of the improvements to Web Forms such as support for EF 6, new Scaffolders and more features which you might not have heard of. We will see how to leverage all of the latest tools in Visual Studio like Browser Link and Web Essentials to make their coding experience simpler, shorter, and more enjoyable. 


ASP.NET MVC 6 (now with integrated Web API!)

Daniel Roth

ASP.NET MVC and ASP.NET Web API in ASP.NET vNext are becoming one singular framework: ASP.NET MVC 6. Join Daniel Roth as he shows how to create great ASP.NET web apps that serve both pages and services. First we'll see how to build OData v4 compliant services using ASP.NET Web API 2.2 and the new attribute routing features available in ASP.NET MVC 5.2. Then we'll take a look at how ASP.NET MVC and Web API are being combined into a single framework, ASP.NET MVC 6, for handling all of your Web UI and services. We'll learn how to use ASP.NET MVC and Web APIs in ASP.NET vNext to support connected applications for browsers, Windows Phone, Windows Store and more!


Entity Framework (v6 and v7 preview)

Rowan Miller

Entity Framework is Microsoft's recommended data access technology for new applications in .NET. We'll explore how the current release of Entity Framework can be used to build applications. We'll also look at an early preview of EF7, a modern, lighter weight, and composable version of Entity Framework (EF) that can be used on a variety of platforms, including ASP.NET vNext, Windows Phone and Windows Store. This new version will also support targeting non-relational data stores.


Taking Your ASP.NET Apps to the Cloud with Microsoft Azure Web Sites

Brady Gaster

Web developers are seeing huge boosts in their productivity building Web Applications with ASP.NET, with so many huge improvements to Visual Studio focused on the problems web developers solve each day. We've also made some significant improvements in Microsoft Azure for web developers by concentrating on providing the community the best cloud in which to host ASP.NET web apps. Features like Auto-scaling and Traffic Management provide high-performance, internationally-distributed web hosting scenarios. We've made it easier than ever to add background processing by adding Azure WebJobs as an option for web developers who need to add a middle tier. Along with staging and production deployment slots, and a rich SDK to enable service automation - a feature many software-as-a-service apps can use to automate their provisioning and deployment experiences - there's no better place than Microsoft Azure Web Sites to host your ASP.NET apps.


ASP.NET Publishing Explained

Sayed Hashimi

The Visual Studio publishing experience for ASP.NET projects has been refined over the past few years. In this talk we will go into detail covering all the different techniques to publish your apps. We will start in Visual Studio, and quickly move to the command line and continuous integration servers. Sayed will you how you can improve your publish process to target multiple environments and how to automate publishing from a CI server. We will also take a look at some of the unique publish workflows that Azure Web Sites supports.


ASP.NET Identity

Pranav Rastogi

ASP.NET Identity is a totally rewritten framework that brings the ASP.NET membership system into the modern era. ASP.NET Identity makes it easier to integrate different authentication systems such as local username, password as well as social logins such as Facebook, Twitter etc. It also gives you greater control over persisting data to your backend technology of choice. ASP.NET Identity is a game changer by bringing in more modern authentication systems such as Two-Factor Authentication. You can use ASP.NET Identity to secure Web Apps as well as Web APIs.


Dependency Injection and Testability in .NET

Mani Subramanian, Francis Cheung

Testability is more important than ever. With short ship cycles and the desire for continuous delivery, it is critical to quickly know if a modification has destabilized your code base. This session will enable you to use a dependency injection container of your choice to create testable code. We will examine tightly coupled code and what problems it causes and how DI can be used to avoid these problems. The Unity DI container will be used as the medium to understand the concepts.



Damian Edwards

SignalR is one of the latest additions to the ASP.NET web stack. It provides real-time HTTP support for your web applications, but the good news is that SignalR is useful outside of a web browser, too. With a client API that's virtually identical in both the JavaScript and native .NET client implementations, developers only need to learn the SignalR abstraction itself to be able to write cross-platform real-time applications. This session will walk through the process of adding real-time functionality to your Windows 8 and Windows Phone 8 apps. We'll also take a look at the scale-out providers and OWIN hosting capabilities available in the latest release of SignalR.


ASP.NET vNext 101

Damian Edwards, David Fowler

ASP.NET vNext is a lean and composable framework for building web and cloud applications. ASP.NET vNext is fully open source and available on GitHub. ASP.NET vNext is currently in preview, and in this talk Fowler and Edwards will put it all into Context. vNext apps can use a cloud-optimized subset of the .NET framework. This subset of the framework is about 11 megabytes in size compared to 200 megabytes for the full framework, and is composed of a collection of NuGet packages. What does that mean for compatibility? When would you choose vNext and when would you not? You don't have to use Visual Studio to develop ASP.NET vNext applications. You can develop and run vNext on platforms that Visual Studio doesn't run on. But Visual Studio provides the best development experience, and we'll cover ASP.NET vNext both inside and outside the IDE.

We encourage you to share this content with your colleagues and friends, and remember that .NET Conf and all its content is free!

Sponsor: Thanks to friends at I use their product and LOVE IT. Get notified of your software’s bugs as they happen! has error tracking solutions for every major programming language and platform - Start a free trial in under a minute!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web

AppVeyor - A good continuous integration system is a joy to behold

May 30, '14 Comments [22] Posted in Learning .NET
Sponsored By

All my open source projects building in AppVeyorEpisode 4 (that's from 2006, people, over 8 years ago!) of the Hanselminutes Podcast was on (CI) Continuous Integration. I was deep into CI at a large bank and having a blast. It's just such a joy to have a reliable and repeatable build. Even more so if setting up that build is easy. A good CI build that includes build, test, and deploy means you don't have to fear your code.

Back in the day we used Batch Files, dreams, and wishes to setup our CI systems. Later we moved to CruiseControl.NET. Today we've got lots of amazing options, some we can download and setup inside the company, and some hosted that require virtually no effort at all!

Like many of you, I've got a number of utilities and open source projects up on GitHub. Mine are at, of course.

However, some are older, some aren't often built, and honestly I couldn't tell you if they build anymore. Sometimes I'll even accept a Pull Request (PR) without really confirming that there isn't a missing semicolon or a syntax error. Ya, I said it. I haven't been nailed yet, but we all do it, and we know it's bad. A reliable CI system that kicks off a build on a commit is the only way to be sure.

I decided to revisit AppVeyor as an option for my CI system. I looked at it 18 months ago and it was time to check it out again.

Just to be clear, they don't know I'm writing this, I don't know AppVeyor, and I don't do paid reviews. This is all my opinion.

AppVeyor says they "automate building, testing and deployment of .NET applications helping your team to focus on delivering great apps."

Cool. I like automate, I like building, testing and deploying. I'm lazy, as are all good developers, so automated all the things!

Their pricing is impressive. It's free for unlimited public repositories, which means I can setup a CI build for all my little utilities and open source projects on GitHub. However, their Pro and Premium options are extremely competitive when compared against running my own VM and CI system in Azure for a month. 

Setting Up

I don't want to gush, but it's simple and gorgeous. I signed up with my GitHub creds (and also added BitBucket as I have some stuff there as well) and made a new project. They automatically sucked in my repositories, as well as the ones I have access to from other organizations. I selected a small one, my WiFi Manager for Windows 8, and clicked New Build.

It cloned my project and started building within a minute. I got an immediate failure, which surprised me.

Specify the Project

I stared at the error for a moment. Ah, my folder has more than one project or solution. Odd, there's just one project. Ah! But there's a foo.csproj AND a foo.sln.

Intuitively I go to Settings | Build, and enter the name of my csproj file. By the time I come back to the dashboard it's building again.

The build dashboard is at the same time impressive and comforting. It looks like a command prompt in HTML and it updates on its own, so you never feel like you're waiting or wondering what's happening.

Build Success

Amazing, look at that. It worked. I can add tests, and identify artifacts (results of the build) and act on them.

Here's my xUnit tests running automatically and their results showing up in the dashboard. Magic.

Tests too!

Here's AppVeyor uploading a build artifact.

Found an artifact

One EXE as Artifact

Here I've added an artifact and can download it and run it right from the browser. If your artifacts are NuGet packages, they'll even give you a private NuGet feed for those artifacts that you can use in other projects or automate yourself!

Finally you can automate deployment to whatever environment you like. Push to Blob Storage (like I do for myEcho), push to a NuGet server, or Web Deploy.

Deploy Anywhere

Impressively, AppVeyor restores NuGet packages as well. It even built a two year old ASP.NET MVC repository of mine on the first try.

So my open source project builds, now what? Now I add a status badge to my project's to let everyone who visits my GitHub repository that this is a healthy project that is building successfully!

Status Badges

It literally took me longer to write this blog post than it did for me to setup Continuous Integration for FOUR open source projects in AppVeyor. Literally about 15 minutes from start to finish.

AppVeyor is really impressive, fun to use, and "just works." It's a great example of Software as a Service and the kinds of software I talked about in my recent post We are abstracting on the shoulders of giants.

With cloud apps like AppVeyor for build/test/deploy, services like like for error management, Trello for products backlogs, FreshDesk for support tickets, there's just so many great choices for a software companies large and small. It's a great time to be writing software.

Related Links

Sponsor: Big thanks to Mindscape for joining us and sponsoring the blog feed this week! I discovered and started using it for my side project and I LOVE it. Get notified of your software’s bugs as they happen! has error tracking solutions for every major programming language and platform - Start a free trial in under a minute!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web

Fixing System.Core 2.0.5 FileLoadException, Portable Libraries and Windows XP support

May 8, '14 Comments [17] Posted in Bugs | Learning .NET | WPF
Sponsored By

Installing Windows XP to testMy buddy Greg and I are getting ready to launch our little side startup, and I was going through our product backlog. Our app consists of a global cloud service with Signalr, an iPhone app made with Xamarin tools, and a WPF app.

One of the items in our Trello backlog was "Support Windows XP. Gasp!"

I hadn't given this item much thought, but I figure it was worth a few hours look. If it was easy, why not, right?

Our WPF desktop application was written for .NET 4.5, which isn't supported on Windows XP.  I want to my app to support as basic and mainstream a .NET 4 installation as possible.

Could I change my app to target .NET 4 directly? I use the new async and await features extensively.

Well, of course, I remembered Microsoft released the Async Targeting Pack (Microsoft.Bcl.Async) through NuGet to do just this. In fact, if I was targeting .NET 3.5 I could use Omer Mor's AsyncBridge for .NET 3.5, so it's good that I have choices.

I changed my project to target .NET 4, rather than 4.5, installed these NuGets, and recompiled. No problem, right?

However, when I run my application on Windows XP it crashes immediately. Fortunately I have instrumented it with so all my crashes to to the cloud for analysis. It gives me this nice summary: is amazing 

Here's the important part:

FileLoadException: Could not load file or assembly 
'System.Core, Version=, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'
or one of its dependencies. The given assembly name or codebase was invalid.
(Exception from HRESULT: 0x80131047)

That's weird, I'm using .NET 4 which includes System.Core version 4.0. I can confirm what's in the GAC (Global Assembly Cache) with this command at the command line. Remember, your computer isn't a black box.

C:\>gacutil /l | find /i "system.core"
System.Core, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL
System.Core, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL

OK, so there isn't even a System.Core version 2.0.5 in the GAC. Turns out that System.Core 2.0.5 is the Portable Libraries version, meant to be used everywhere (that means, Silverlight, etc, everywhere) so they made the version number compatible.

Because we're building our iPhone app with Xamarin tools and we anticipate supporting other platforms, we use a Portable Library to share code. But, it seems that support for Portable Libraries were enabled on .NET 4 vanilla by the KB2468871 update.

I don't want to require any specific patch level or hotfixes. While this .NET 4 framework update was pushed to machines via Windows Update, for now I want to support the most basic install if I can. So if the issue is Portable Libraries (which I still want to use) then I'll want to bring those shared files in another way.

You can LINK source code in Visual Studio when you Add File by clicking the little dropdown and then Add as Link:

Adding source code as a Link within Visual Studio

Now my Messages.cs file is a link. See the little shortcut overlay in blue?

A linked file as a little overlay on the icon

I removed the project reference to the Portable Library for this WPF application and brought the code in this way. I'm still sharing core, but just not as a binary for this one application.

Recompile and redeploy and magically .NET 4 WPF application with async/await and MahApps.Metro styling starts up and runs wonderfully on this 12 year old OS with just .NET 4 installed.

For our application this means that my market just got opened up a little and now I can sell my product to the millions of pirated and forever unpatched Windows XP machines in the world. Which is a good thing.

Sponsor: Big thanks to Aspose for sponsoring the blog feed this week. Aspose.Total for .NET has all the APIs you need to create, manipulate and convert Microsoft Office documents and a host of other file formats in your applications. Curious? Start a free trial today.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web
Page 1 of 30 in the Learning .NET category Next Page

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.