有个项目中需要将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.
帖子链接: