运行时错误引用VBA程序集从C# [英] Runtime error referencing VBA assembly from C#

查看:328
本文介绍了运行时错误引用VBA程序集从C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#.NET 3.5项目,不幸的是依赖于几个VB6 ActiveX控件。

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

到目前为止,我已经能够愉快地访问数据容器

Up until now I have been able to happily access the data containers and methods defined in the ActiveX controls by simply adding a reference to the controls in my project and referencing them as normal.

但是,我今天打了一个钩子,当我不得不打电话给我的电话一个方法返回一个VBA.Collection。

However I hit a snag today when I had to call a method that returns a VBA.Collection.

我的代码将编译没有问题,但在运行时我得到以下错误:

My code will compile with no problem, but at runtime I get the following error:


无法加载文件或程序集Interop.VBA,Version = 6.0.0.0,Culture = neutral,PublicKeyToken = null'或其中的一个依赖项。系统找不到指定的文件。

Could not 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 file specified.

我有Interop.VBA(6.0.0.0版本)和Interop.VBRUN 6.0.0.0)在我的项目,任何想法?

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

我不能给出具体的代码,它涵盖在NDA。

I can't give specific code, it is covered under an NDA.

但是,这里是来自对象浏览器的示例代码,其名称已更改以保护不那么无害的

However, here is sample code from object browser with 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 can call this method I get the error message above at runtime:

Collection BadMethod();

所以它调用的方法返回一个VBA.Collection导致的问题。
这些是我无法控制的第三方控件,它们不会在.net中重写。

So it the call to the method that returns a VBA.Collection that causes the issue. These are 3rd party controls that I have no control over and they will not be rewritten in .net

编辑:虚拟项目在VS2010和工作完美如预期,所以似乎这可能是VS2012的问题。我看到一些帖子,暗示在2012年没有正确创建VBA的interops,所以我会去看看我能找到那里...

edit: Out of interest I went and tried a quick dummy project in VS2010 and worked perfectly as expected, so it appears that this may be an issue with VS2012. I've seen some posts that hint at 2012 not creating interops for VBA correctly, so I'll go see what I can find there ...

推荐答案

感谢@Jeremy Thompson将我放在正确的轨道上,运行进程监视器显示我的应用程序无法找到interop.VBA.dll文件,一旦固定一切正常工作。不知道为什么这在2010年而不是2012年,但很高兴有一个解决方案

Thanks to @Jeremy Thompson for putting me on the right track, running process monitor showed me that my application was unable to locate the interop.VBA.dll file, once that was fixed everything works as expected. No idea why this works out of the box on 2010 and not 2012, but happy to have a solution

这篇关于运行时错误引用VBA程序集从C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆