1

I have been recently having trouble with a run-time error:-

Could not load type 'ADODB.FieldsToInternalFieldsMarshaler' from assembly my_assembly

which I am endeavouring to correct with the advice given here, here and here. But doing this (setting Embed Interop Types=false, Copy Local=true, and Isolated=false) has caused numerous compilation error messages:-

Option Strict On disallows implicit conversions from 'ADODB.Recordset' to 'ADODB.Recordset'

These occur when a recordset is passed as a ByRef parameter.

The suggested cure...

CType(my_record_set, ADODB.Recordset)

results in another error of the same type, which will presumably require an infinite number of CTypes to cure. However, the Daily-WTF nature of the error message and the fact this compiled perfectly well before making the project-related changes leads me to the conclusion that the code isn't really the problem; it is something to do with this work-round.

So does anyone know what the problem is with the work-round, or how to fix the compilation errors the suggested solution causes?

EDIT The code where the error manifests itself:-

Dim record_set As ADODB.Recordset = Nothing
query_string = "some sql-server query"
db_error = Database.DoQuery(query_string, record_set) ' Error in this line

where the database class has

Public MustOverride Function DoQuery(
                       ByVal query_string As String, _
                       ByRef record_set As ADODB.Recordset) As DATABASE_ERRORS

and the particular override is:-

Public Overrides Function DoQuery(
                     ByVal query_string As String, _
                     ByRef record_set As ADODB.Recordset) As DATABASE_ERRORS
    record_set = New ADODB.Recordset
    record_set.CursorLocation = ADODB.CursorLocationEnum.adUseClient
    record_set.Open(query_string,
                    database_connection,
                    ADODB.CursorTypeEnum.adOpenStatic,
                    ,
                    ADODB.CommandTypeEnum.adCmdText)
End Function

(Error handling omitted for brevity).

Community
  • 1
  • 1
Brian Hooper
  • 21,544
  • 24
  • 88
  • 139
  • This error (the second one) is certainly curious. Can you please post more relevant code such that we can replicate your conditions? What is the type of my_record_set? One thing is an error in the DB connection (first error you refer) and a different story is a type-casting error (second error). – varocarbas Oct 24 '13 at 08:36
  • @varocarbas, I have added a code sample. But I'm wondering if the compilation error is a bit of a red herring, and the problem may lie in the `Embed Interop Types` etc. settings. – Brian Hooper Oct 24 '13 at 09:34
  • Your code seems OK (it executes OK). The error you refer (the second one... although not sure where are you exactly using the cast) is very weird and thus indicative of something not going too right. I don't know what to say... I cannot replicate your conditions. – varocarbas Oct 24 '13 at 10:54
  • You are welcome. Didn't make a big deal of try (copy code + execute) but was curious about a so peculiar error. Perhaps you should provide more information regarding your exact conditions for anyone willing to spend a bit longer on this :) – varocarbas Oct 24 '13 at 11:30
  • Idea candidate for a bounty. Provide more info about the original error, so it can be reproduced, then offer a bounty. – Steve Oct 24 '13 at 15:08

1 Answers1

1

I came here for a similar problem but the library that was referenced is our own. I found the solution here and deleting the reference to the compiled library solved it for me. It seems the vb.net compiler gets confused by having both the compiled version and the source referenced in the same solution.