Question

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

Was it helpful?

Solution

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.

OTHER TIPS

I'm pretty sure that when you reference COM components in this way, the COM component import happens every time you build. That means that the COM component must be registered the traditional way on every machine the project will be built on.

Here's a link that describes using registration free com interop. If you've already done this please post your manifest file. You might have a typo your missing.

Edit

Just a thought might be simpler to just register the dll the first time the app runs on a new machine. Registration free com interopt is only available on Windows XP and newer so if your targeting any dinosaurs out there it won't work.

Here's an excerpt from the Troubleshooting section of an MSDN article on reg-free COM. Apologies if you've already seen it. The good news is you are already part of the way through the steps. It suggests reproducing the problem in Windows Server 2003 (maybe with Virtual PC?) and then the event log should help.

First get ... your client working with a registered server; then unregister the server and verify that your error message is what you expected; and finally... craft and deploy manifest files. This way your troubleshooting efforts ... will be confined to the structure of your manifest files (and the correct embedding of the assembly manifest if you choose to do so).

When troubleshooting registration-free COM issues, the Event Viewer on Windows Server 2003 is your friend... look in the System Event Log for events from the COM server. I don't suggest that you look at the Windows XP Event Log... it will invariably contain a message... which doesn't help identify the problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top