Monthly Archives: March 2014

Preparing for 70-496: Administering Visual Studio Team Foundation Server 2012

I am finally trying to make some time to study for and pass this exam. I thought I’d write down my progress and study plan in case other people find it interesting. First of all you should head to the Microsoft site for this exam:

http://www.microsoft.com/learning/en-us/exam-70-496.aspx

Since I am a self-paced training kinda guy I’ll start with the Jump Start course (which is free). I already know quiet a lot about TFS so this probably won’t be much of a challenge. I also don’t think it will be enough to pass the exam.

http://www.microsoftvirtualacademy.com/training-courses/administering-visual-studio-tfs-2012-exam-496-jump-start

After this I am going to go through the measures skills categories one at a time. I could download Brian Keller’s excellent TFS VM’s (http://blogs.msdn.com/b/briankel/archive/2013/08/02/visual-studio-2013-application-lifecycle-management-virtual-machine-and-hands-on-labs-demo-scripts.aspx), but since the first category of measures skills is “Installation and Configuration” I think I’ll create a VM myself.

More on that later.

ClosedXml exception when opening an Excel sheet.

We handle may Excel sheets in our automated systems and we use the great ClosedXml opensource library (https://closedxml.codeplex.com/). However today we stumbled upon a sheet that crashed one of our applications.

InvalidOperationException: Sequence contains no matching elements.

After downloading the ClosedXml source I found out the sheet had a rogue comment. Somehow this comment did not have the shapetype that ClosedXml expected. After removing it everything ran smoothly again.

It seems I am, for the first time, going to make a bugfix contribution to an opensource project….

Is your KnockoutJS ‘options’ binding working on IE11 but not on IE8?

I had this issue, and since I am not a javascript expert, it took me a while to figure this out.

If you are binding to a static array (declared in code) like such:

self.statusOptions = [
        { name: "Option 1", id: 1 },
        { name: "Option 2", id: 2 },
        { name: "Option 3", id: 3 },
    ];

This will go horribly wrong because the that final comma. In IE 8 this means there is another, empty, item in the array. In IE11 this seems to work fine. So change it to this and you are good to go:

self.statusOptions = [
        { name: "Option 1", id: 1 },
        { name: "Option 2", id: 2 },
        { name: "Option 3", id: 3 }
    ];

How to apply Web.config transformations during TFS build.

Just a simple reminder to myself, because I already had to look this up twice:

If you want a project’s web.config files to use transformations as it would when you hit deploy in VS, you need to set the following MSBuild arguments in your Team Build definition:

/p:UseWPP_CopyWebApplication=True /p:PipelineDependsOnBuild=False

And it looks like this:

Legacy and .NET interop on x86 vs x64

The problem

When writing .NET applications that need to interoperate with (legacy) 32-bit ODBC drivers, COM libraries and such. You might run into problems on 64-bit OS installations. By default applications written using the .NET Framework 4 or earlier will be compiled with the “Platform Target” option as “Any CPU”. When such an application accesses a 32-bit COM component on a 64-bit machine you might see the following kind of exception:

This operation failed because the QueryInterface call on the COM component for the interface with IID ‘{YOUR-GUID-HERE}’ failed due to the following error: Old format or invalid type library. (Exception from HRESULT: 0x80028019 (TYPE_E_UNSUPFORMAT)).

When trying to access and ODBC connection you might find that there are 64-bits and 32-bits ODBC connections. And that older drivers can only be used for 32-bits ODBC connections.

Solution 1

If you catch this during in-house testing you will be able to fix the problems by forcing the compiler to use the x86 platform. By going to the project properties, than go to the “Build” tab and setting the “Platform Target” to “x86” like so:

However, be aware that this is a configuration specific setting, so if you are wondering why your release builds are still giving you these problems you should also apply this setting for the Release configuration.

If all of the components in your solution should be built using the x86 platform target or if you want to be able to create separate x64 and x86 builds it is probably better to create solution platforms for both. You can do this by right clicking on the solution and choosing “Configuration Manager”:

Here you can create custom solution platforms and allow you to select the project’s platform for each of your projects.

Solution 2

If you are using the .NET Framework 4.5 from the start of your project you might have noticed you do not run into the above problems. This is because of a new setting that is on by default called “Prefer 32-bit” (this settings was conveniently greyed out for met .NET Framework 4 project screenshot above).

If it is possible to upgrade to the .NET Framework 4.5 then this is a much cleaner way of dealing with things. Though just upgrading is not enough, after the upgrade you DO need to actually check the box to enable it.

More info on this option can be found here: http://blogs.microsoft.co.il/sasha/2012/04/04/what-anycpu-really-means-as-of-net-45-and-visual-studio-11/

Solution 3

So what if you shipped your product built in .NET 4.0 and the Platform set to “Any CPU”. The customer might not want to upgrade to your new and improved version, and you don’t want to rebuild the version he is using. Or you just found out and a release with the fix might be months away (and of course the customer can’t wait that long).

When that happens it is time to fall back to solution number 3: CorFlags.exe which is a tool installed with Visual Studio and is available from the “Developer Command Prompt”.

This tool allows you to edit the header section of your .NET executable. And can be used in the following way:

CorFlags.exe MyApp.exe /32BIT+
or
CorFlags.exe MyApp.exe /32BIT+ /Force

The latter is used if you have a strong signed assembly. This will break the signing so be careful with that. More info on the tool can be found here: http://msdn.microsoft.com/en-us/library/ms164699(v=vs.110).aspx