Issue passing .NET object from VB6 to .NET

时光总嘲笑我的痴心妄想 提交于 2019-12-19 11:26:59

问题


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

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.

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?


回答1:


You problem is the different NET versions as you said.

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

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

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>

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



来源:https://stackoverflow.com/questions/41116078/issue-passing-net-object-from-vb6-to-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!