I want to add a registration-free COM reference to my .NET app. Registration-free means users can run the app without registering the COM component to their system.
I found a number of articles on this topic (e.g. MSDN, this S/O question, etc.) but none contains concrete steps. Here's what I have tried and did not work:
foo.dll
) using mt.exe as described in this answer.foo.dll
and foo.dll.manifest
to my app as "Build Action" = "Content" and "Copy to Output Directory" = "Copy Always".interop.foo.dll
that came with foo.dll
.Add app manifest file with this section:
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="foo" />
</dependentAssembly>
</dependency>
Build and run.
There's an error saying application configuration is not correct. Tried different values in <assemblyIdentity>
without luck.
Could someone share experience? Thanks.
Registration-free COM interop activates a component without using the Windows registry to store assembly information. Instead of registering a component on a computer during deployment, you create Win32-style manifest files at design time that contain information about binding and activation.
NET Framework to create COM components, you can use registration-free COM interop.
Hans's answer has the right information, but I wasn't clear what to do when I first read it. After trying many different things I finally got it working and it's very simple:
By following these steps, the interop.foo.dll
and app manifest are automatically generated. This allows users to use the COM component without registration.
On the opposite, if you don't register the COM on the dev machine, you can still develop and build the app by adding reference to interop.foo.dll
(which can be generated on a machine with the COM class registered and then copied around), but the build result can only run on machines with the COM component registered. There might be a solution around this but requires deeper knowledge of how MSBuild work with COM references, which I did not spend time investigating.
So in short, the key to runtime registration-free COM is to register the COM class on the dev machine.
Your manifest is not correct. It should contain the <file>
element instead of the <dependentAssembly>
element. With <comClass>
elements that declare the creatable co-classes.
Generating the manifest is a built-in feature in the VS build system. To make it work, the COM component needs to be installed correctly on your dev machine. Do not try a reg-free COM manifest unless you can make it work without one on your machine, you'll fight two problems instead of one. So for starters make sure that the server is properly installed, using the vendor's installer or deployment instructions. And make sure that a test program that creates an object and call a method operates correctly.
Exercising this is useful, with a known-good COM server that's available on any machine. Create a new project from the Console Application project template. Project + Add Reference, Browse tab, select c:\windows\system32\shell32.dll. Select the added Shell32 reference and change its Isolated property to True. Build + Rebuild.
Look in the bin\Debug build directory of your project and open the app.exe.manifest file with Notepad. Observe the file and comClass elements, that's what you'll need in yours as well. If this doesn't help then turn to the owner of the COM server, he should be able to provide you with the manifest you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With