Microsoft KB Archive/837378

= BUG: You receive a &quot;Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall&quot; error message when you make a late-bound call in Visual Basic .NET =

Article ID: 837378

Article Last Modified on 5/17/2007

-

APPLIES TO


 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition

-





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,  is a placeholder for the actual path where the application is saved. In the application module,  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
 Start Visual Basic 6.0. On the File menu, click New Project.

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

By default, the Class1 class is created.  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  On the File menu, click Save Class1.cls, and then click Save Project As. In the File name box, type the name of the project. On the File menu, click Make .dll.

The Make Project dialog box appears.

Note  is a placeholder for the actual name of the project.</li> Click OK.</li></ol>

Create a console application
<ol> Start Visual Studio .NET.</li> On the File menu, point to New, and then click Project.

The New Project dialog box appears.</li> Under Project Types, click Visual Basic Projects.</li> Under Templates, click Console Application.</li> Click OK.

By default, the Module1.vb module is created.</li>  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) = &quot;name&quot; args(1) = &quot;num&quot; 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(&quot;cedrbank&quot;, BindingFlags.InvokeMethod, Nothing, x, args, c, Nothing, Nothing) Console.WriteLine(args(2)) dc = New CurrencyWrapper(6)

'Use the CurrencyWrapper type. x.cedrbank(&quot;name&quot;, &quot;num&quot;, dc) Console.WriteLine(dc)

'Force 'd' to be passed ByVal by using parentheses around 'd.' x.cedrbank(&quot;name&quot;, &quot;num&quot;, (d)) Console.WriteLine(d)

End Sub

End Module </li> Add a reference to the DLL that you created in the &quot;Create a DLL by using Visual Basic 6.0&quot; section of this article.</li> On the Build menu, click Build Solution.</li> On the Debug menu, click Start.

You do not receive the error message that is mentioned in the &quot;Symptoms&quot; section of this article.</li></ol>

<div class="status_section">

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

<div class="moreinformation_section">

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

Create a console application
<ol> Start Visual Studio .NET.</li> On the File menu, point to New, and then click Project.

The New Project dialog box appears.</li> Under Project Types, click Visual Basic Projects.</li> Under Templates, click Console Application.</li> Click OK.

By default, the Module1.vb module is created.</li> <li> 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) = &quot;name&quot; args(1) = &quot;num&quot; args(2) = d

x.GetType.InvokeMember(&quot;cedrbank&quot;, BindingFlags.InvokeMethod, Nothing, x, args)

Console.WriteLine(d)

x.cedrbank(&quot;name&quot;, &quot;num&quot;, d)

Console.WriteLine(d)

End Sub

End Module </li> <li>Add a reference to the DLL that you created in the &quot;Create a DLL by Using Visual Basic 6.0&quot; section of this article.</li> <li>On the Build menu, click Build Solution.</li> <li>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.</li> <li>On the Just-In-Time Debugging dialog box, click No.

You receive the error message that is mentioned in the &quot;Symptoms&quot; section of this article.</li></ol>

<div class="references_section">