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 开发者_StackOverflowthe 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???
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:
- .NET 4.0 behaves differently than .NET 3.5 (which it does, I've found)
- The "Embedded Interop Types" isn't working properly for that COM object (ADO 2.8)
- Something I did in the break out caused it
I happened to try #2 first and it fixed it.
精彩评论