BUG: You receive a "Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall" error message when you make a late-bound call in Visual Basic .NET (837378)



The information in this article applies to:

  • Microsoft Visual Basic .NET (2003)
  • Microsoft Visual Basic .NET (2002)

SYMPTOMS

When you make a late-bound call in Microsoft Visual Basic .NET, the late-binding support fails when the ByRef decimal is converted to ByRef currency. You receive the following error message:
Unhandled Exception: System.Runtime.InteropServices.COMException (0x80020005): Type mismatch. at Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack, Boolean IgnoreReturn) at Microsoft.VisualBasic.CompilerServices.LateBinding.LateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack) at ConsoleApplication2.Module1.main() in C:\ConsoleApplication\Module.vb:line number

Press any key to continue
Note In this error message, C:\ConsoleApplication\Module.vb:line number is a placeholder for the actual path where the application is saved. In the application module, line number represents the line where the error occurs.

WORKAROUND

To work around this bug, use either of the following options:
  • Use the CurrencyWrapper type.
  • Force the decimal value to be passed by using the ByVal keyword.

    To do this, put parentheses around the variable that contains the decimal value.
To implement either of these workaround options, create a DLL by using Visual Basic 6.0, create a console application, and reference the DLL in the console application, as follows:

Create a DLL by using Visual Basic 6.0

  1. Start Visual Basic 6.0.
  2. On the File menu, click New Project.

    The New Project dialog box appears.
  3. Click ActiveX DLL, and then click OK.

    By default, the Class1 class is created.
  4. Add the following code to the Class1 class:
    Public Function cedrbank(name As String, ACCNUM As String, ACCBAL As Currency) As Long
    
    MsgBox ACCBAL
    
    ACCBAL = 4.321
    
    End Function
  5. On the File menu, click Save Class1.cls, and then click Save Project As.
  6. In the File name box, type the name of the project.
  7. On the File menu, click Make Project.dll.

    The Make Project dialog box appears.

    Note Project is a placeholder for the actual name of the project.
  8. Click OK.

Create a console application

  1. Start Visual Studio .NET.
  2. On the File menu, point to New, and then click Project.

    The New Project dialog box appears.
  3. Under Project Types, click Visual Basic Projects.
  4. Under Templates, click Console Application.
  5. Click OK.

    By default, the Module1.vb module is created.
  6. Replace the existing code in the Module1.vb module with the following code:
    Imports System
    Imports System.Runtime.InteropServices
    Imports System.Reflection
    Imports Project1
    Public Module Module1
    
        Sub Main()
    
            Dim x As Object
            x = New Class1
            Dim dc As Object = New CurrencyWrapper(5)
            Dim d As Decimal = 1.987
            Dim args(2) As Object
    
            args(0) = "name"
            args(1) = "num"
            args(2) = dc
    
    
            Dim c(0) As Reflection.ParameterModifier
            c(0) = New Reflection.ParameterModifier(3)
            c(0).Item(0) = True
            c(0).Item(1) = True
            c(0).Item(2) = True
    
            CObj(x).GetType().InvokeMember("cedrbank", BindingFlags.InvokeMethod, Nothing, x, args, c, Nothing, Nothing)
            Console.WriteLine(args(2))
            dc = New CurrencyWrapper(6)
    
    
            'Use the CurrencyWrapper type.
            x.cedrbank("name", "num", dc)
            Console.WriteLine(dc)
    
            'Force 'd' to be passed ByVal by using parentheses around 'd.'
            x.cedrbank("name", "num", (d))
            Console.WriteLine(d)
    
        End Sub
    
    End Module
    
  7. Add a reference to the DLL that you created in the "Create a DLL by using Visual Basic 6.0" section of this article.
  8. On the Build menu, click Build Solution.
  9. On the Debug menu, click Start.

    You do not receive the error message that is mentioned in the "Symptoms" section of this article.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to reproduce the behavior

To reproduce the behavior, create a DLL by using the steps that are mentioned in the "Create a DLL by using Visual Basic 6.0" section of this article, and then create a console application, as follows.

Create a console application

  1. Start Visual Studio .NET.
  2. On the File menu, point to New, and then click Project.

    The New Project dialog box appears.
  3. Under Project Types, click Visual Basic Projects.
  4. Under Templates, click Console Application.
  5. Click OK.

    By default, the Module1.vb module is created.
  6. Replace the existing code in the Module1.vb module with the following code:
    Imports System
    Imports System.Runtime.InteropServices
    Imports System.Reflection
    Imports Project1
    
    Public Module Module1
    
    
        Sub main()
    
            Dim x As Object
    
            x = New Class1
    
            Dim d As Decimal = 1.987
    
            Dim args(2) As Object
            args(0) = "name"
            args(1) = "num"
            args(2) = d
    
            x.GetType().InvokeMember("cedrbank", BindingFlags.InvokeMethod, Nothing, x, args)
    
            Console.WriteLine(d)
    
            x.cedrbank("name", "num", d)
    
            Console.WriteLine(d)
    
        End Sub
    
    End Module
    
  7. Add a reference to the DLL that you created in the "Create a DLL by Using Visual Basic 6.0" section of this article.
  8. On the Build menu, click Build Solution.
  9. On the Debug menu, click Start Without Debugging.

    A message box appears that contains the 1.987 text. Next, the Just-In-Time Debugging dialog box appears.
  10. On the Just-In-Time Debugging dialog box, click No.

    You receive the error message that is mentioned in the "Symptoms" section of this article.

Modification Type:MinorLast Reviewed:2/9/2006
Keywords:kbvs2005swept kbvs2005doesnotapply kbvs2002sp1sweep kbMarshal kbManaged kbbug KB837378 kbAudDeveloper