BC31094 Error with MSBuild but not Visual Studio

      Comments Off on BC31094 Error with MSBuild but not Visual Studio

Here’s one of those things that “can’t possibly happen” but does. The project builds fine under the Visual Studio 2008 IDE, but if I run it directly under MSBuild.exe it fails with the error

error BC31094: Implementing class 'MMCLTSVCS.FooClass' for interface 'MMCLTSVCS.Foo' cannot be found.

The key is that the error involves calling a COM object. The project contains a reference to the interop for that COM object: Interop.MMCLTSVCS.dll. However it does not contain a reference to the interop for one of the other COM objects that Interop.MMCLTSVCS.dll uses. Apparently this works fine under the IDE but fails with an obscure error message under MSBuild.

Visual Studio’s “Unused References” function provides an easy way to get this error. It will helpfully remove any references that are not used by your .NET code, without considering whether they are used by any of the referenced interops.