views:

207

answers:

2

I'm maintaining a WPF based application which contains a WinForms based WebBrowser control that based on the IE web browser control. When we deploy, we have had to also supply Microsoft.mshtml.dll and do some custom configuration stuff for our ClickOnce publishing process as well in order to get things to work.

I'm curious that with the new NoPIA and Type Equivalence features and dynamic type capabilities in C# 4.0 can we expect that if we upgrade that we can remove the dependencies on the Microsoft.mshtml.dll assembly? If so this will not only reduce the size of our deployment quite a bit but will also simplify our publishing process as well.

It is my understanding that we should be able embed the types that normally get automatically generated into extra assemblies for COM types such as the MapPoint Control by Visual Studio. I don't know if this also applies to the Microsoft.mshtml.dll or even how it is done even in the most simple of cases. If somebody could provide an explanation about what the practical impact of these new features are on a project that relies on COM interop and especially the Microsoft.mshtml.dll assembly it would be of great help to me.

+1  A: 

C# 4.0 can we expect that if we upgrade that we can remove the dependencies on the Microsoft.mshtml.dll assembly?

You will still need the dependency to build your assembly, but it is not needed at runtime (and VS will not copy it to the output directory)

Providing you have set the "Embed Interop Types" setting in the properties of the reference to MSHTML set to "True".

Richard
+2  A: 

Absolutely, that's what it is all about. Import your solution into VS2010, Project + Properties, Application tab, change the Target Framework to .NET 4.0. Open the References node in the Solution Explorer window, select the Microsoft.mshtml reference and set its "Embed Interop Type" property to True. It is automatically turned on for new projects that target 4.0

This works for any COM type library that you selected on the COM tab as well as any PIA you selected in the .NET tab. The type library is only required at build time, you don't have to deploy the interop libraries or PIAs anymore. The actual COM server must of course still be present on the target machine.

The new dynamic keyword and the optional and named argument features are not related, they merely make it easier to write cleaner code when working with COM servers that were designed to work with scripting languages. Mshtml is already pretty clean, Office interop is the best example.

Also note that it tends to be easy to avoid taking a dependency on mshtml when you leverage the Windows Forms' HtmlDocument and HtmlElement classes. That gets started by using the WebBrowser.Document property. They however don't wrap all mshtml features.

Hans Passant
Thanks for the added details about Windows Forms' HtmlDocument and HtmlElement classes. This will probably help others who are may be viewing this post. I believe in our case we needed access to some of the more obscure events and properties that unfortunately are not exposed by these types.
jpierson