COM Interop registration failed.

I’m currently at a client where they use Excel extensivly. They use C++ libraries for heavy calculations, C# for some other libraries and if I’m correct, VB6 to let Excel speak to all those libraries. A pretty wicked configuration, if you ask me. Worth mentioning is that they tried talking from within (managed) C# to the (unmanaged) C++ code and made a lot of calls to the other side. A lot. They were kind of surprised that it was so slow.

But anyway, the problem was that although the C# code was compiling properly, increasing build numbers every time, inside every assembly a reference to a specific interface assembly was wrong, referencing and old version. This was the error we got:

COM Interop registration failed. Type library exporter encountered an error while processing ‘xxx’. Error: Type library exporter can not load type (error: System.IO.FileLoadException: The located assembly’s manifest definition with name ‘yyy’ does not match the assembly reference.

The solution to this is, to remove all references to the specific assembly and shut down Visual Studio. VS.NET 2001 in our case.
Then load up VS.NET again and add the references again. Then it should work.

It seems that VS.NET imports the Type Library of the COM enabled assembly when adding a referencing to it. When you just remove the reference and add it immediatly again, the old Type Library remains in memory and it’s not updated.

One of those things you just have to know. Luckely for our client, Richard van der Pal did know and helped us out!