Monday, May 24, 2010

Want to write Managed IE/Shell Extensions, but thought that was “bad”? That was the past… With .Net 4 the world of Managed Extensions is now open to you.

vcsjones - Writing a Managed Internet Explorer Extension: Part 1

“I’ve recently had the pleasure of writing an Internet Explorer add on. I found this to somewhat difficult for a few reasons and decided to document my findings here.

Managed vs Native

One difficult decision I had to make even before I had to write a single line of code was what do I write it with? I am a C# developer, and would prefer to stay in that world if possible. However, this add-on had the intention of being use commercially, and couldn’t make the decision solely based on preference.

Add-on’s to Internet Explorer are called Browser Helper Objects, often documented as BHOs as well. They are COM types, thus if we were going to do this managed, we will be doing some COM Interop. I’ve done this before, but mostly from a level of tinkering or deciding to go back to native. The .NET Framework had another benefit to me, and that was WPF. My BHO requires an user interface, and doing that natively isn’t as easy or elegant as using native libraries. Ultimately I decided to go with .NET Framework 4.0, and I can only recommend the .NET Framework 4.

Previous versions of the CLR has a serious drawback when exposing the types to COM: They always used the latest version of the CLR on the machine. If you wrote a BHO in the .NET Framework 1.1, and 2.0 was installed, it would load the assembly using the .NET Framework 2.0. This can lead to unexpected behavior. Starting in the .NET Framework 4, COM Visible types are guaranteed to run against the CLR they were compile with.

image …”

In the recent past, writing Managed Extensions has been frowned upon, and pretty much off limits, due to lack of in-process side-by-side support in the CLR. The first Extension would load the CLR it needed and all later Extensions in the process would have to use that CLR version. Period.

That was the past…

.Net 4’s support for in-process side-by-side CLR versions means that once scary place of writing Managed IE/Windows Shell extensions is now open, available AND supported.

Forget what you knew, you CAN, with .Net 4, write Managed IE/Shell extensions. So what are you waiting for?  ;)


Related Past Post XRef:
Taking your first steps with spicIE
Spice up your IE with spicIE – Writing IE7/8 Plugins in managed code in minutes (beta)

No comments: