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)
SYMPTOMSWhen 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. WORKAROUNDTo 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
Project.dll.
The Make
Project dialog box appears.
Note Project is a placeholder for the actual
name of the project. - Click OK.
Create a console application- Start Visual Studio .NET.
- On the File menu, point to
New, and then click Project.
The
New Project dialog box appears. - Under Project Types, click Visual
Basic Projects.
- Under Templates, click Console
Application.
- Click OK.
By default, the
Module1.vb module is created. - 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
- Add a reference to the DLL that you created in the "Create
a DLL by using Visual Basic 6.0" section of this article.
- On the Build menu, click Build
Solution.
- 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.
REFERENCESFor more information, visit the following Microsoft Web
sites:
Modification Type: | Minor | Last Reviewed: | 2/9/2006 |
---|
Keywords: | kbvs2005swept kbvs2005doesnotapply kbvs2002sp1sweep kbMarshal kbManaged kbbug KB837378 kbAudDeveloper |
---|
|