Compiler-Error: error MSB3217

How an orphaned assembly in the GAC can cause the misleading MSB3217 'Cannot register assembly' build error and why removing stale dependencies solves it.

Since several days during compilation i had the error:

Cannot register assembly "Foo.dll".
Exception has been thrown by the target of an invocation.

In the output-window with diagnostic compile information the following statement was listed:

Foo -> Foo.dll
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(2731,9):
error MSB3217: Cannot register assembly "Foo.dll".
Exception has been thrown by the target of an invocation.
Done building project "Foo.csproj" -- FAILED.

Manually registration was no problem.

The solution was an orphaned assembly in the GAC. This assembly was referenced by my project (by a roundabout) and referenced self other assemblies which are deleted. Normally a local copy should be used, but the compiler takes the version of the GAC (GAC-assemblies are preferred over local assemblies) and so the compiler runs in a problem.

Fretfully was the wrong hint “cannot register assembly” :-(