Tuesday, August 16, 2011

How to register COM-class within the application manifest file

You don't always need to register referenced COM-classes in the windows registry. Sometimes it's much more simple and reliable to use application manifest for referencing COM-classes. This feature is called Registration-free COM and well described in this article.
In few words, you can add application manifest file to you .NET application project (Add New Item -> Application Manifest File). Then you can reference COM this way:
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <file name="MyPrivateCOM.dll">
    <comClass clsid="{AC78B8E2-6C4D-11d1-ADE2-0000F8754B99}" threadingModel="Apartment" />
 </file>
</asmv1:assembly>


* This source code was highlighted with Source Code Highlighter.
I provided a simplified version of the manifest file with a COM-reference only. Though, it's correct and working sample. Of course, application manifests allows to do much more than just referencing COM-classes, but it's an another big and interesting topic.

No comments:

Post a Comment