Ian Boyd
Ian Boyd

Reputation: 256999

Registration-Free COM from ASP.NET?

Windows allows use of a COM object without having to register the COM dll.

The mechanism is to include a "dependent assembly" in the application's manifest:

MyProgram.exe.manifest

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
  <assemblyIdentity type="win32" name="myapp.exe" version="1.2.3.4" />
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32" name="Contoso.Frobber" version="5.1.81.4" />
    </dependentAssembly>
  </dependency>
</assembly>

And then your folder contains:

with the COM dll's assembly manifest containing:

Contoso.Frobber.manifest

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">

   <assemblyIdentity type="win32" name="Contoso.Frobber" version="1.0.0.0" />

   <file name = "confrob.dll">

      <comClass
            progid="Frobber.Gizmo"
            clsid="{00028C00-0000-0000-0000-000000000046}"
            description="Gizmo Frobber by Contoso"
            threadingModel = "Apartment" />

      <typelib 
            tlbid="{00028C01-0000-0000-0000-000000000046}"
            version="1.0" 
            helpdir=""/>
   </file>
</assembly>

Excellent. i can now use a COM object from a (native or .NET) executable without having to register the COM object.

Now i want to use a COM object from an ASP.NET web-site, without registering the COM object.

Possible?


Bonus Chatter

Windows also allows an exe to call a .NET library, without having to install the .NET assembly into the Global Assembly Cache.

Upvotes: 5

Views: 2773

Answers (2)

David C
David C

Reputation: 26

Recently we were handling a similar case that we needed to enable Side by Side COM(reg-free COM) in IIS hosted ASP.NET core application, and we made it like:

  1. embed the manifest to an assembly(.dll)
  2. use CreateActCtx() to activate the manifest.

This approach works fine and it's recommended by MS .NET Runtime Interop Team.

Upvotes: 1

Yahia
Yahia

Reputation: 70379

Although I can't test it right now I am pretty sure that this works:

IF the manifest for a DLL is external it will usually be ignored when the DLL is loaded via LoadLibrary (according to MSDN). IF the manifest is embedded into the DLL it is usually honored.

Embed the manifest into the ASP.NET application (i.e. code-behind DLL) - for some ways on how to do this see here and here and here.

UPDATE - as per comments:

The above is a workaround as there is no general way to do this (isolation), at least the ASP.NET creators haven't intended this to be possible - for example the above workaround won't work in cases where the application does not compile to a DLL...

Upvotes: 3

Related Questions