Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

So I am trying to register and use a .NET library that I have created in C#.NET and up until now I have been getting Visual Studios to "Register COM" on build.

I am now trying to go through the process of a how I might deploy so I have the following which registers the DLL:

"%windir%\Microsoft.NET\Framework\v4.0.30319\"regasm.exe "%~dp0myDLL.dll"

This is Windows XP and the folder with the batch script above and the myDLL.dll sits on the desktop.

which registers the DLL file, but when I come to add a reference to it in VBA I am getting the following:

Error in loading DLL

I can see the library in the References list and the location looks correct.

What am I doing wrong?

share|improve this question

2 Answers

If you don't use Regasm's /codebase option (like the IDE does) then you will also need to register the assembly in the GAC with gacutil.exe. Which also requires giving the DLL a strong name. Note that gacutil.exe is not available on a machine that doesn't have the Windows SDK installed.

The desktop is certainly a bad place to put COM servers, way too easy for them to disappear and produce a hard to diagnose error message. Like this one. Realistically, COM servers require an installer.

share|improve this answer
Will give it a go. The only reason I put it on the desktop was to ensure it wasn't a strange permissions issue. – Ben 18 hours ago
I got the same error. – Ben 18 hours ago
Use SysInternals' ProcMon utility, it shows you exactly what registry keys are being used and what files are getting loaded. If you've got a file in a wrong directory then it will show you that in the trace, searching for the file in the wrong place and not finding it. – Hans Passant 18 hours ago
Will give it a go. I've noticed that when I unregister the DLL. It is still visible in the references list – Ben 18 hours ago
Sure, your VBA project doesn't know that the DLL disappeared. It also doesn't know that you changed it, refreshing the reference after making changes is a hard requirement. Also a reason for this error message. – Hans Passant 18 hours ago
show 2 more comments

The answer can be found here: "Register for COM Interop" vs "Make assembly COM visible"

I needed: regasm.exe /codebase /tlb path-to-dll.dll

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.