2

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:

  • MyProgram.exe
  • MyProgram.exe.manifest (if you're using an external manifest; could also be embedded at RT_MANIFEST resource)
  • Contoso.Frobber.manifest (the COM DLL manifest)
  • confrob.dll (the dll containing the COM classes we want to use)

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.

JohnFx
  • 33,720
  • 18
  • 99
  • 158
Ian Boyd
  • 220,884
  • 228
  • 805
  • 1,125
  • What makes you think it's not possible? – RB. Feb 06 '12 at 15:50
  • 1
    @RB The program that wants to depend on an unregistered DLL needs to declare that dependancy in it's manifest (`MyProgram.exe.manifest` in my original example). In the case of ASP.NET, the program that i would have to manfiest is `w3wp.exe`, creating `w3wp.exe.manifest` and place it in `Program Files`. i shouldn't be manifesting *all* www worker processes; i only want to manifest my "web-site". And i see no way to *"manifest a web-site"*. – Ian Boyd Feb 06 '12 at 21:47
  • I'm not sure what you are trying to do. This is an old DAO-based visual control, so at best you might use it client-side in its unbound mode. Reg-free COM does not apply and isn't required. There is a way to load such an ActiveX control in IE via the tag from a CAB file on your site, as long as you create and specify a license package (LPK) file for the page too. Even this assumes relaxed security in IE though. – Bob77 Feb 07 '12 at 16:59
  • `dbgrid32.ocx` was only an example to help people understand what registration-free COM is used for. i will replace `dbgrid32.ocx` with the filename i'm actually using. It doesn't change the question or the concepts - although might make it more difficult for people to understand what i'm asking. – Ian Boyd Feb 07 '12 at 20:46
  • Perhaps you can dig an answer out of this: [Isolating ASP .Net 2.0 Applications](http://www.mazecomputer.com/sxs/help/iis6aspnet2.htm) – Bob77 Feb 08 '12 at 02:48

1 Answers1

3

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...

Community
  • 1
  • 1
Yahia
  • 67,016
  • 7
  • 102
  • 131
  • i would really rather not modify the global `asp.net.dll`. Aside from it likely being a protected file, which cannot be modified, invaliding it's security signature, using [a global solution to solve a local problem](http://blogs.msdn.com/b/oldnewthing/archive/2008/12/11/9193695.aspx), it would mean that i could not have different web-sites isolated with different versions of the COM dll (e.g. Live and Test) – Ian Boyd Feb 08 '12 at 19:21
  • If asp.net web-sites cannot use any of the Windows mechanisms for isloation - then that's the answer. Don't be afraid to say, "No, it cannot be done. ASP.net doesn't support isolated binaries." – Ian Boyd Feb 08 '12 at 19:24
  • @IanBoyd I am NOT talking about the global `asp.net.dll` - I would strongly advise against doing that! My recommendation was to modify YOUR ASP.NET application which is itself a DLL which in turn loads/uses the COM component if I understand your scenario correctly... – Yahia Feb 08 '12 at 19:30
  • @IanBoyd As I wrote above: I can't test this currently... but I would think it is possible as described (putting the manifest into your application/code-behind DLL)... – Yahia Feb 08 '12 at 19:31
  • @IanBoyd updated my answer to clarify this point explicitely. – Yahia Feb 08 '12 at 19:35
  • Ahh, that makes more sense. Although it only would work for web-sites that compile to an assembly dll. i think the better answer is, "Cannot be done" - since the designers of ASP.net have no intended way to support isolation. – Ian Boyd Feb 08 '12 at 19:43