Runtime error referencing VBA assembly from C #

I have a C # .NET 3.5 project which, unfortunately, relies on a couple of VB6 ActiveX controls.

Until now, I could happily access the data containers and methods defined in ActiveX controls by simply adding a link to the controls in my project and referring to them as usual.

However, today I fell into the trap when I had to call a method that returns VBA.Collection.

My code will compile without problems, but at runtime I get the following error:

Failed to load file or assembly 'Interop.VBA, Version = 6.0.0.0, Culture = neutral, PublicKeyToken = null' or one of its dependencies. The system cannot find the specified file.

I have links to Interop.VBA (version 6.0.0.0) and Interop.VBRUN (version 6.0.0.0) in my project, any thoughts?

I can’t give a specific code, it is distributed under the NDA.

However, here is a sample code from the object’s browser with the names changed to protect the not so innocent;)

I can reference the following properties and methods from my code:

ReturnConstants GoodMethod(); string prop1 ReturnConstants prop2 

If I try to call this method, I get the error message above at runtime:

 Collection BadMethod(); 

So, this is a method call that returns VBA.Collection, which causes the problem. These are third-party controls that I have no control over, and they will not be overwritten in .net

edit: Out of interest, I went and tried the quick dummy of the VS2010 project and worked perfectly as expected, so it seems like this could be a problem with VS2012. I saw several posts that hinted that 2012 will not correctly create transitions for VBA, so I'll go see what I can find there ...

+2
source share
1 answer

Thanks to @Jeremy Thompson for putting me on the correct track, a working process monitor showed me that my application could not find the interop.VBA.dll file, as soon as this was fixed, everything worked as expected. I don’t know why it works out of the box in 2010, and not in 2012, but I’m glad to have a solution

+2
source

Source: https://habr.com/ru/post/980992/


All Articles