Tuesday, August 7, 2012

How to handle Microsoft.mshtml.dll

The assembly Microsoft.mshtml.dll is not part of the .Net installation, and so not generally available on the machines you install your software to.
It is distributed with Visual Studio, and installed to the GAC, which is why this issue will often not be descovered until you deploy.

This is how I handle the issue.

First, copy the dll to the 'imports' folder in your souce control tree. (You should do this with all your dependencies anyway). This will ensure that it can be found on any other machine, such as a build server, which may not have VS installed.

Then, when you add a reference to the dll, be sure to browse to the import location. In the properties of the reference, set 'Embed Interop Types' to False and 'Copy Local' to True. This will copy the dll to the output directory, so that it will be available, and not have to be separately installed on client machines.