views:

729

answers:

2

I'm trying to use a .NET assembly from VB6 via interop without placing it in the GAC and without using the /codebase argument for regasm.exe.

From what I understand, when I run regasm.exe on a .NET class library, it creates a registry entry for each class in the class library telling the COM clients they should load mscoree.dll that serves as a proxy wrapping .NET objects for COM use. Mscoree.dll uses the InprocServer32/Assembly key in the registry for the class to determine which class library contains the implementation of the class.

If I use /codebase with regasm.exe or put my class library in the GAC, everything works OK; but as far as I can figure out from the scattered documentation, mscoree.dll should look for the assembly in the current directory and in the path if /codebase hasn't been used (and therefore there is no CodeBase entry in the registry for the class) and it can't find it in the GAC.

The C# code is as simple as can be:

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace myinterop
{
    [Guid("B1D6B9FE-A4C7-11DD-B06B-E93056D89593")]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    [ComVisible(true)]
    public class MyServer
    {
        public int Add(int a, int b)
        {
            return a + b;
        }
    }
}

And the problem reproduces with a VBScript one liner that I put in the same directory as the compiled DLL:

object = CreateObject("myinterop.MyServer")

What am I missing here? Is there a definitive description of the way mscoree.dll looks up the assemblies somewhere?

BTW, I'm using .NET 2.0 and yes, I know I should put my assemblies in the GAC, I'm just wondering why this doesn't work as advertised.

+2  A: 

From MSDN:

/Codebase : Creates a Codebase entry in the registry. The Codebase entry specifies the file path for an assembly that is not installed in the global assembly cache. You should not specify this option if you will subsequently install the assembly that you are registering into the global assembly cache. The assemblyFile argument that you specify with the /codebase option must be a strong-named assembly.

It appears that it does work as advertised. If you don't put your assembly in the GAC, then you need to use /codebase so that the filepath is accessible.

OJ
+2  A: 

To achieve what you want, I think you need to create .manifest files for both your .NET assembly and your VB6_App.EXE (referencing the .NET assembly). Check Google for registration-free COM.

jkchong
Didn't know you could do that. Cool!
gooli