Surface 2.0 SDK Migration and PowerToy Blues with “Object not set to an instance of an object”

New Microsoft® Surface® 2.0 SDK has been released along with the Microsoft® Surface® Migration Power Toy which is aimed at helping all the Surface 1.0 code to the new SDK.

There have been numerous changes in the new SDK to play along with the WPF 4 and its integrated touch support. The Power Toy is there to help migrate all the Surface 1.0 code with a very low estimated manual work needed for seamless transition.

I tried the Power Toy and immediately hit the brick wall. I kept getting a failure from the tool.

Error: Project "System.__ComObject" could not be loaded. Error: Object not set to an instance of an object.

When I dug a little deeper in the source code it turned out that one specific case was not handled properly. Luckily there is a simple fix without getting much deeper into understanding the specifics of the code. There is a method RemoveReference() in ProjectExtensions.cs on line 31 that is doing a C# “as” instead of a cast but not checking for a null. Actually, “as” is perfectly valid here but the null check is definitely missing. All of my Surface 1.0 projects have a “Miscellaneous Files” Project but these do not cast to VSProject and thus the exception.

Luckily, all that needs to be done is to just add a single line of code and all starts working beautifully. Add the following on line 34 and life will be good again.

            if (vsProject == null) return false;

Hopefully this saves someone a sleepless night. Cheers!

kick it on

Tags: , , , ,

  1. Onir’s avatar

    Thanks! Very helpful! :)



Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>