23

I have a .NET 2.0 COM object that's used by VBA in Excel. It works fine on my dev machine, but when trying to use it on a clean VM workstation I get this error:

Automation error. The system cannot find the file specified.

The dll is registered with "regasm /tlb /codebase mycom.dll" and not put in the GAC. I don't have administration rights on the VM box

Any ideas?

1
  • 1
    Is your COM the correct platform? I made my own .dll to be used from Excel VBA. And I got this exact message because I compiled it for x64 instead of x86. Commented Jul 25, 2018 at 4:22

5 Answers 5

18

You need to either invoke regasm with the full path to the assembly as the codebase parameter value or put the assembly into some location which is always on the path for searching libraries. Otherwise it will not be found when the client tries to instantiate the COM object.

Sign up to request clarification or add additional context in comments.

4 Comments

I did try using regasm on the full path of the assembly which is located in c:\temp, but still the same error
Then I guess your best bet is to start ProcessMonitor - technet.microsoft.com/ru-ru/sysinternals/bb896645.aspx - and look what file exactly is not found. It could be some dependent assembly you're not at all aware of. Once you know for sure it will be much easier to resolve.
sharptooth, thank you very much for this answer. It saved my hide today!
I know that is an old question but it is worth a try, i have the same problem, and my question is do i have to run regasm for every dependency dll?
8

On windows 7, 64 bit and a .NET 4.0 framework dll (32 bit) that I want to be usable as a COM object for a Microsoft Excel 2010 VBA application, here is what worked for me.

  1. Copy the dll to c:\windows\syswow64
  2. In a cmd shell, run

    C:\Windows\Microsoft.NET\Framework\v4.0.<whatever you have>\regasm.exe c:\windows\syswow64\<name of dll> /codebase /tlb:c:\windows\syswow64\<name of dll minus '.dll'>.tlb
    

You can skip the last part (/tlb:. . .) if you don't want or need intellisense on the machine you are registering the assembly on.

The key hangup I had is that on XP I never had to use the /codebase parameter before but that was the key thing needed before this worked.

Comments

8

I received this "Automation error. The system cannot find the file specified" error after I had created a .NET .dll (v4.0) with the intention of using it in a VB6 application (decorated my class with "ClassInterface" and "ComVisible" attributes, methods with "ComVisible").

I ran "regasm.exe -tlb C:\PathTo\MyDll.dll" but received the above error after adding the .tlb file as a reference in my VB6 application and running/debugging it. Only after adding the "-codebase" parameter to the regasm.exe call and re-adding the .tlb reference did the error get resolved.

Just thought I'd share my experience.

Comments

1

I also receive a automation error. My reference (in MS Access) was to a TLB file. The corresponding DLL file was missing from the folder that held the TLB file and this caused the 'automation error' message to appear. Adding the DLL back in fixed.

Comments

1

I was getting the same error (could not consume the .NET object from legacy VB6 cod on a second dev machine, after it was working on a first machine where I originally wrote it). The .NET DLL compiled and registered just fine - I tried all sorts of combinations - with and without using the "Register for COM Interop" build setting in VS; manually registering via regasm.exe and trying this both with and without the /codebase parameter; tried both enabling and suppressing the COM Visible assembly-level attribute (when suppressing, I set the attribute on the class I need to consume from COM). But nothing worked, I kept getting the same error.

Turns out I had upgraded the DLL output to .NET 4.5 on the second machine, whereas it was originally building a .NET 2.0 assembly. My project had a few references targeting 3rd party Interop DLLs that were running .NET 2.0. When I either updated these references and rebuilt the DLL -or- set my project back to run on .NET 2.0 - my problem was solved. When using /codebase (which VS does automatically) I found that I did not need to put my DLL in the application directory or in \syswow64. Also the MSDN docs state you must use a SN (strong name) for your assembly when using /codebase, but I found you don't have to; you just get a warning from the regasm.exe command line tool.

The point is, from a COM Interop standpoint, be careful about the .NET runtime version of your dependencies with respect to the .NET Framework you are targeting.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.