Excel .NET COM - Automation error. The system cannot find the file specified

前端 未结 5 819
名媛妹妹
名媛妹妹 2021-02-12 11:43

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:

Automat

5条回答
  •  一整个雨季
    2021-02-12 12:25

    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.

提交回复
热议问题