使用经典 ADO 的 Recordset.Type 属性的 MissingMethodException
在我的 ASP.NET 应用程序中,我使用经典的 ADO 2.8 将一些数据保存到 Access 数据库中。 (或者是 Jet 数据库,对于那些坚持认为 Access 只是前端的人来说。)所以我有一个包含一些数据的 RecordSet,并且我想设置某些字段的值,但首先我需要知道字段类型。因此,我使用 Recordset.Type 属性:
Dim fieldType = rs("MyField").Type
这意外地导致错误: MissingMethodException 未由用户代码处理 -- 错误:缺少方法 'instance valuetype ADODB.DataTypeEnum [MyProjectName] ADODB.Field:: get_Type()' 来自类'ADODB.InternalField'。
考虑到是 .NET 本身创建了 .NET/COM 互操作程序集,知道为什么吗?
最奇怪的事情是:当调试器停止并报告错误并将我带到代码中发生错误的位置时,它具有一个很棒的功能,您可以将鼠标悬停在任何变量等上,它会显示其错误value——所以我将鼠标悬停在 rs("MyField").Type 部分上,你瞧,它显示了正确的值!
因此,如果它可以在调试时对其进行评估,为什么它会在运行时抛出错误???
In my ASP.NET app, I'm using classic ADO 2.8 to save some data into an Access database. (Or a Jet database, for those who insist that Access is just the front-end.) So I have a RecordSet containing some data, and I want to set the value for some fields, but first I need to know the field type. So I use the Recordset.Type property:
Dim fieldType = rs("MyField").Type
And that unexpectedly results in an error: MissingMethodException was unhandled by user code -- Error: Missing method 'instance valuetype ADODB.DataTypeEnum [MyProjectName] ADODB.Field::get_Type()' from class 'ADODB.InternalField'.
Considering that it is .NET itself that has created the .NET/COM interop assembly, any idea why?
And here's the strangest thing: When the debugger stops and reports the error and takes me to the spot in my code where it happened, and it has that great feature by which you can hover the mouse over any variable etc. and it will show its value -- so I hover over the rs("MyField").Type
part, and, lo and behold, it shows the correct value!
So if it could evaluate it at debug-time, why did it throw an error at run-time???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在VS2010中的VB.NET中遇到了这个问题。我不知道 ASP.NET,也不知道您使用的是哪个版本的 Visual Studio,但我通过关闭项目中该 COM 引用的“嵌入式互操作类型”属性来修复它。我猜这是一个错误。
至于我是如何找到解决方案的:当代码位于主项目中时,它在 .NET 3.5 中运行良好。当我将“通用”代码分解为独立库,将其转换为 4.0,并开始使用“嵌入式互操作类型”时,我开始遇到问题。这意味着以下三件事之一导致了它:
我碰巧首先尝试了#2,它修复了它。
I ran into this problem in VB.NET in VS2010. I don't know ASP.NET, nor what version of Visual Studio you are using, but I fixed it by turning off the "Embedded Interop Types" property for that COM reference in the project. I'm guessing this is a bug.
As to how I found the solution: It worked fine in .NET 3.5 when the code was in the main project. When I broke the "Common" code out into a standalone library, converted it to 4.0, and started using the "Embedded Interop Types", I started having the problem. That meant one of three things caused it:
I happened to try #2 first and it fixed it.