R – How to use Reg-Free COM for a vb6 dll reference in a .net project

comnetregfreecomvb6

I've been trying to solve this issue for a long time, and nothing seems to work.

I have a COM DLL written in vb6. I add a reference to this DLL in .net, with the 'isolated' and 'copy local' properties set to true on the reference. Apparently this is supposed to enable reg-free com.

But it doesn't work. If I try on another computer, or unregister the DLL with regsvr32, trying to access the DLL throws an exception (essentially saying the desired com class does not exist). The DLL and manifest files are in the same folder as the EXE, but it apparently just totally ignores them.

What am I doing wrong? I've read a ton of scattered articles about this but none of them give me a working solution. I've tinkered with visual studio to no avail. I've tinkered a small amount with make-my-manifest, but it didn't work (even on a test project).

Best Answer

I was creating and using the com class on a non-ui thread. Apparently Reg-Free com on vb6 DLLs doesn't work in that situation. This test code shows it:

Private Sub RunTest() Handles Button1.Click
    Try
        Dim x As New RegTestProject.RegTestCall
        MsgBox(x.RegTestFunction())
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub

Private Sub RunThreadedTest() Handles Button2.Click
    'fails if reg-free COM is used'
    Dim t As New Threading.Thread(AddressOf RunTest)
    t.Start()
End Sub

When I run this with the DLL registered normally, both tests succeed. If I use reg-free com, the threaded test fails even though the normal test still succeeds. Looks like this is going to be a huge pain to work-around.

Related Topic