Wednesday, September 9, 2009

Install Microsoft.mshtml on client machines using ClickOnce

I had recently published an application using ClickOnce which used MS Office Primary Interop Assemblies. When a user tried to install it, he got an error :

MSHTML Error

I was surprise at first as I was not at all using Microsoft.mshtml in my application. As it turned out, the PIA's refer to this dll internally. As I have Visual Studion installed in my workstation, the Microsoft.mshtml had got added to my GAC and the appliaction worked fine on my workstation. People who have not installed Visual Studio or .NET Framework SDK dont have it in there GAC hence the error. Now that I found the problem, I had to find a solution.

Tried to force users to install .NET Framework SDK by setting it as Prerequisite in ClickOnce (under Publish -> PreRequisite) solved the issue but it does not make much sense to ask users to download a 350+ MB package and install it just to get a dll. There has to be a easy way out.

So I started thinking of alternatives. Any application looks for dlls in GAC only after it has looked in to the current directory. The solution was to push Microsoft.mshtml.dll in to the bin directory.
By default if you go to Project Properties -> Publish -> Application Files you will see something like :

app files

Clickonce correctly identifies Microsoft.mshtml.dll as a prerequisite but has marked "None" as the dowload group i.e. it does not get downloaded to the user's machine. To enable it going in to the user's machine, you can just mark the Publish Status of the dll to "Include (Auto)" . You will see the download group automatically being changed to "(Required)". Now publish it.
Clickonce will now identify the dll as a required download dll so will download it to the user's workstation. While installation, the Interop dll's will find Microsoft.mshtml.dll in their current directory hence will no longer look in to GAC for the dll and the install will go on smoothly.

And this is a cheaper a better solution too.

No comments: