invokeMember object does not match target type错误解决办法

4 篇文章 0 订阅

有个项目中需要将C#写的dll中产生一个事件event,然后C++程序调用,并注册回调事件。触发事件的时候,报了个错,而在开发者机器上又没有出现,开始以为是环境问题,可是又找不到具体是哪个环境没装,最后将vs在目标机器上装了,还是不行,,,结果是将C#程序在那机器上编译一逼,才没有出现。。。所以这个问题还是没有解决(不可能每个机子都去编译一遍吧!!!)

网上找了很久,终于在bing上搜到一个帖子,搞得,不容易啊,不得不感谢外国人。。。,有些问题还是得靠英文搜索啊。

我的搜索的关机字就是“invokeMember object does not match target type”,以下是帖子的核心内容。

This is a threading issue, I think.

The call to Completed is of course a call to a COM object. The call is probably marshalled to another thread in the COM than the main thread, which will produce the error "Object does not match target type".

Instead of this:

if ( this.Completed != null )
    this.Completed( true );

...try this:

if ( this.Completed != null )
    Invoke(Completed, new object[] { true });

Take a look at the documentation for the InvokeRequired property.

 An alternative approach would be to declare the Completed method as static in VB.

帖子链接:

https://social.msdn.microsoft.com/Forums/vstudio/en-US/e3a3930f-fa50-4959-8d51-2e345a8214bf/object-does-not-match-target-type-when-raising-an-event-from-c-to-vb6

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值