将.NET对象从VB6传递到.NET的问题 [英] Issue passing .NET object from VB6 to .NET

查看:64
本文介绍了将.NET对象从VB6传递到.NET的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个由第三方创建的.NET dll A。它通过tlb将类公开给我们的VB6 exe应用程序。

We have a .NET dll "A" that is created by a third party. It exposes classes through a tlb to our VB6 exe application.

我们也有自己的.NET dll B,它引用了.NET dll A。

We also have our own .NET dll "B" that references .NET dll "A". "B" also exposes classes to our VB6 exe application through a tlb.

现在,VB6应用程序在使用VB6代码中的任何一个库中的类之前都没有问题,直到我们尝试调用 B中具有参数类型为 A的函数。在那种情况下,我们会收到错误430或错误消息无法将类型为'system .__ comobject'的com对象转换为类型为'Type.From.Dll.A'

Now, the VB6 application has no problem using classes from either library in the VB6 code until we try to call a function in "B" that has a parameter type from "A". In that case, we get an error 430 or an error saying "unable to cast com object of type 'system.__comobject' to type 'Type.From.Dll.A'"

是什么原因造成的?这是正常的吗?

What could be causing this? Is this normal?

推荐答案

您的问题是您所说的.NET版本不同。

You problem is the different NET versions as you said.

在版本4中,NET团队引入了进程内并行执行

In version 4 , the NET team introduced the In-Process Side-by-Side Execution

使用此功能,您可以拥有不同版本的在您的应用程序中运行CLR。

With this you can have different versions of the CLR running in your application.

但这不是您想要的,所以我认为您应该使用app.config文件关闭此功能:

But that is not what you want, so I think you should turn this feature off, using an app.config file:

<?xml version="1.0"?>
<configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0"/>
    </startup>
</configuration>

请注意,在使用VB6 IDE时,需要app.config的过程是VB6.exe,因此我还将该app.config复制到VB6文件夹,并将其重命名为VB6.exe.config。 查看此答案

Please note, that while you are using the VB6 IDE, the process that requires an app.config is the VB6.exe, so I would also copy that app.config to the VB6 folder and renamed it as VB6.exe.config. See this answer

这篇关于将.NET对象从VB6传递到.NET的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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