Search code examples
.netdllcomassembliesregasm

Error (0x80070002) when dll is not in the same path from registration


First, the question is similar to Deploying .NET COM dll, getting error (0x80070002) but it didn't answer my problem.

I have build a dll (.net4) that I use with VBA in Excel / Word.

Principle:

  • I register the dll with regasm.exe from a temporary folder (no problem)

    RegAsm.exe `C:\temp\install\mydll.dll` /codebase
    
  • When Excel / Word load, the document (excel or word) load the dll in references

    Call ThisWorkbook.VBProject.References.AddFromFile("C:\working\anyfolder\mydll.tlb")
    

The folderpath can change depending the user (he create documents where he wants), and he can send documents to other users (if the dll is not in the folder, the document works in a degraded mode.

All of this works fine.

My problem: Recently I decided to improve the installation of this dll. When the installation finish I add a clean of the installation folder (C:\temp\install). But after doing that, when I try to use my dll in Excel / Word I have the error 0x80070002 File not found, even if the dll is in the folder of use (it's the same version of the dll I register)

What I know: I understood that he want the dll in the installation folder.

What I want:

  • Is there a way, after registration with regasm, to delete dll from installation folder and only use the one in the folder of documents (and move the dll from folder to folder depending needs).
  • Should I take a look at the GAC ? (I read the GAC wasn't needed if the dll is in the same folder as the document)

I read regasm documentation but found no information about it

If any other information is needed to anwser this, don't hesitate to ask.

Thanks a lot

update

To solve my problem, during the installation I add an installation to the GAC

(new Publish()).GacInstall("C:\temp\install\mydll.dll")

Publish needs a reference to System.EnterpriseServices


Solution

  • The COM DLL needs to be present in the folder it was registered from all the time. You can use it in any application, but the Windows system needs to be able to find the DLL.

    Your specific problem sounds like you should look into Office addin development.


    There are little exceptions like Microsoft Dynamics NAV 5 that also require the DLL be present in the same folder as the application's executable, but I guess that's just a flaw in design and shouldn't normally be the case (in Dynamics: If you use the COM class both from the classic client and an application server, the COM-DLL needs to be present both in the classic-folder and the application server folder).