如何找到产生“类型不匹配"的arg? -VB .NET中的DISP_E_TYPEMISMATCH异常 [英] how to find the arg that generates "Type mismatch" - DISP_E_TYPEMISMATCH exception in VB .NET

查看:79
本文介绍了如何找到产生“类型不匹配"的arg? -VB .NET中的DISP_E_TYPEMISMATCH异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到了可怕的类型不匹配"信息,尝试调用COM对象API时发生异常.如果我使用对象",则在VB中工作正常,但在VB .NET中失败.如果将对象强制转换为强类型的COM对象,则可以调用相同的API.什么 最常见的异常是最令人沮丧的是,生成的异常不知道是什么参数导致了异常.方法可以有多个参数,即使不是不可能,也很难确定哪个参数. 如果消息字符串说类型与参数xxx不匹配-预期的整数类型,但被传递了Long",那将是一个很好的选择.也就是说,某人的某处代码检测到类型问题,因此该代码知道哪个参数以及什么参数. 预期的类型是.如果异常字符串可以传达更多有用的信息,那将节省大量时间.照原样,我有客户端和服务器代码,但仍然无法确定哪个参数导致了问题.我最近追逐了其中之一 问题是长"字样.net中的64位.经过大量的试验和错误编程之后,我找到了解决该问题的方法-将Int32用作COM API接受的10个左右参数之一的变量类型.现在在这里我再次猜测 由于几乎没有用的异常消息而在参数上出现问题.


研发荷兰(Holland)

I am getting the dreaded "type mismatch" exception when trying to call into a COM object API. Worked fine in VB but fails in VB .NET if I use "Object". I can call the same API if I cast the object to the strongly typed COM object. What is most frustrating with this all too common exception is that the exception generated gives no clue about what parameter is causing the exception. Methods can have more than one parameter making determination of which argument very hard, if not impossible. Wouldn't it be rather nice if the message string said "Type mismatch with argument xxx - expected type of Integer but was passed a Long". That is, somewhere someone has code that detected the type issue and hence that code knows which argument and what the expected type is. If the exception string could convey more useful information that would be a great time saver. As it is, I have the client and the server code and still I cannot determine which argument is causing an issue. I chased one of these down recently and the problem was that a "Long" in .net is 64 bits. After a lot of trial and error programming, I hit upon the solution in that cause - use Int32 for a variable type for one of the 10 or so arguments the COM API took. Now here I am again guessing at arguments thanks to a nearly useless exception message.


R.D. Holland

推荐答案

我认为这里的任何人都无法对错误消息的有用性做任何事情.如果您发布API的详细信息以及如何调用它,我们也许可以发现问题.也许如果您发布在VB 6中有效的呼叫以及 .Net出现故障.
I don't think anyone here can do anything about the usefulness of the error message. If you post details of the API and how you are trying to call it, we may be able to spot the problem. Perhaps if you post the call that worked in VB 6 and the call that is failing in .Net.


这篇关于如何找到产生“类型不匹配"的arg? -VB .NET中的DISP_E_TYPEMISMATCH异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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