How to investigate/debug Microsoft Fakes build error

By default an error during the generation of a new fake assembly from Visual Studio 2012 Microsoft Fakes will generate no output but for:

Build started: Project: MyUnitTest, Configuration: Debug Any CPU ——
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========

To debug the build issue, open the assembly.fake xml file in the Fakes folder added automatically to your project. Add the two parameters Diagnostic=”true” Verbosity=”Noisy” to the fake element, like this:

<Fakesxmlns=http://schemas.microsoft.com/fakes/2011/Diagnostic=trueVerbosity=Noisy>

<AssemblyName=Microsoft.Hpc.SchedulerVersion=2.0.0.0/>

</Fakes>

Then in Tools|Options under Projects and Solutions|Build and Run, change the MSBuild project output verbosity to ‘Diagnostic’. Build again and in the generated output, look for Task “GenerateFakes”

For me it allowed to see useful information such as:

Unhandled Exception: Microsoft.QualityTools.Testing.Fakes.Engine.CodeGeneration.UnstubableException: Could not resolve assembly ‘Microsoft.Hpc.Scheduler.Store, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’. Are you missing an assembly reference? (TaskId:14)

And btw, the Scheduler.Store assembly can be found in the GAC after installing the HPC client utilities and SDK.

As this post is fairly popular, let me augment it with an example on how to avoid build warnings from Microsoft fakes on common libraries.

While fakes are useful, the current implementation is a bit annoying in that it generates a build warning for everything it could found through inspection but couldn’t generate a stub or shim for. If you have as a rule that build warnings on your project should be 0, that ain’t cool. But, you typically don’t need the fakes on every type of the faked assembly, just a few select one. So you can modify the fake configuration xml to indicate just the stubs and shims you need, and ‘clear’ the rest. Then you won’t get build warnings.

Here is an example for the HPC Scheduler assembly:

<Fakesxmlns=http://schemas.microsoft.com/fakes/2011/Diagnostic =true>

<AssemblyName=Microsoft.Hpc.SchedulerVersion=2.0.0.0/>

<StubGeneration>

<Clear/>

<AddFullName=Microsoft.Hpc.Scheduler.ISchedulerJob/>

<AddFullName=Microsoft.Hpc.Scheduler.ISchedulerTask/>

<AddFullName=Microsoft.Hpc.Scheduler.ISchedulerNode/>

<AddFullName=Microsoft.Hpc.Scheduler.ISchedulerCore/>

<AddFullName=Microsoft.Hpc.Scheduler.SchedulerTask/>

<RemoveTypeName=SchedulerTaskCounters />

</StubGeneration>

<ShimGeneration>

<Clear/>

<AddFullName=Microsoft.Hpc.Scheduler.Scheduler/>

<AddFullName=Microsoft.Hpc.Scheduler.SchedulerTask/>

<AddFullName=Microsoft.Hpc.Scheduler.NameValue/>

<RemoveTypeName=SchedulerCoreState />

<RemoveTypeName=SchedulerRowEnumerator />

<RemoveTypeName=SchedulerRowSet />

</ShimGeneration>

</Fakes>

This entry was posted in Computers and Internet, Microsoft, Ordinateurs et Internet, Travail, work. Bookmark the permalink.

1 Response to How to investigate/debug Microsoft Fakes build error

  1. daviburg says:

    As this post is fairly popular, I’ve augmented it with an example on how to avoid build warnings from Microsoft fakes on common libraries.

Leave a comment