This project is read-only.

Multiple Handlers per assembly?

Apr 4, 2013 at 2:49 PM
So I was trying out both this library and a commercial library for doing managed shell extensions. The commercial library ( allows you to include several classes in the same assembly/project which is really useful for things like icon overlays. I think it does this because it makes you to write your own [ComRegisterFunction] and [ComUnregisterFunction] and use provided helper methods to explicitly register each extension class, so only a single method in the assembly has either attribute. But in SharpShell the ComRegisterFunction is abstracted in SharpShellServer so each handler I try to register has it's own function with that attribute. The code compiles fine and both register functions are called if registering the server via regasm, but the SharpShell test server doesn't load it and the handlers don't work in practice. I assume this is because the shell doesn't load the assembly correctly because having multiple functions with [ComRegisterFunction] causes COM incompatibility? So with that, there's no way with SharpShell to write multiple handler classes in a project and build them into one assembly.

Is my understanding is the issue correct, is that why it won't work? Either way, is there some non-obvious way around the limitation?
Apr 4, 2013 at 4:48 PM

This is indeed an interesting issue - it's always been my plan to be able to implement multiple extensions in a single class library but so far it's an untested scenario. It sounds from what you've that the issue is indeed multiple registration functions. However, I'm convinced that this is an issue that could be circumnavigated. I will raise a task for this for the next release of SharpShell and see what can be done.

Releases are happening every few weeks at the moment, so I'll hopefully have a resolution for this soon.
Apr 4, 2013 at 4:49 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Apr 5, 2013 at 6:57 AM
I also thought this was a problem, but actually multiple handlers work fine from single assembly. At least for icon overlay handlers on windows 7. I simply mark each class with its own appropriate com registration attributes, and guid and voila it works. The only problem is that the server registration tool that comes with a project doesn't work for this scenario, but using regasm, as you would in your final deployment, does everything as designed.

Now as to Server Registration tool, the root of the problem is in ServerManagerApi
var server = container.GetExport<ISharpShellServer>().Value;
Doesn't account for possibility of multiple exports, so System.ComponentModel.Composition.ImportCardinalityMismatchException is thrown and so the gui complains (and lies :P). And the rest of the gui tool doesn't seem to have support for this scenario... but the important Com registration functionality works if you use regasm, so I'm totally happy.. thought you might find this useful.
Apr 5, 2013 at 9:09 AM
Thanks for the heads up - the latest cut of the code which is has resolved this issue - now all of the exports are loaded from the assembly, not just a single export :)