Visual Basic Q&A

As a software engineer, I focus on .NET, especially asp.net, C#, WCF and so on, and I am also very interested in Search Engine Optimization.

Entries Tagged ‘unhandled exception’

BUG: Error at run time after you upgrade a Microsoft Visual Basic 6.0 project that uses the ImageList control to Microsoft Visual Basic .NET

Symptoms
When you upgrade a Microsoft Visual Basic 6.0 project that uses the ImageList control to a Microsoft Visual Basic .NET project by using the Microsoft Visual Basic .NET Upgrade Wizard, you receive the following exception when you run the project in Visual Basic .NET:

An unhandled exception of type ‘System.Runtime.InteropServices.COMException’ occurred in axinterop.mscomctllib.dll
Resolution
The Visual Basic .NET Upgrade Wizard wraps the ImageList control in the AxHost class. However, it does not modify the corresponding Visual Basic 6.0 code to access the underlying ImageList control. For example, the following code may be part of the migrated Visual Basic .NET code.

ListView1.ColumnHeaderIcons = ImageList

PRB: Error When You Access an Array Field of a .NET Structure from COM

Symptoms
When you access an Array field of a structure that is defined in .NET from inside a COM DLL, you may receive the following error message:

“An unhandled exception of type ‘System.ArgumentException’ occurred in ProjectName”
Additional information: Wrong number of arguments or invalid property assignment.
Resolution
Because of the late-bound method that is used in this case, the Visual Basic 6.0 runtime cannot get the type information for the Array field that you are attempting to access.

BUG: The SelectionMode poperty of the data-bound ListBox control or of the CheckedListBox control does not prompt you to provide a valid value

Symptoms
When you set the SelectionMode property of the data-bound ListBox control or of the data-bound CheckedListBox control to NONE in the Microsoft Windows Form Designer, you receive the following error message:

Invalid property value If you click OK in the message box, you set the SelectionMode property to NONE. However, you might not expect the SelectionMode property to be set to NONE. The Form Designer does not prompt you to provide a valid value.
Note When you run the Windows application after you set the SelectionMode property to NONE, you receive the following error message:

An unhandled exception of type ‘System.ArgumentException’ occurred in system.windows.forms.dll
Additional information: Cannot call this method when SelectionMode is SelectionMode.NONE.
Resolution
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

BUG: Error message when you set the Width property of a Boolean DataGrid column to 1 in Visual Basic .NET or in Visual C# .NET: “System.ArgumentException”

Symptoms
You bind a DataGrid control to a data source that has a column with Boolean data. If you set the Width property of the DataGrid Boolean column to 1 at run time, you receive the following exception:

An unhandled exception of type ‘System.ArgumentException’ occurred in system.windows.forms.dll
Additional information: Invalid parameter used.
Resolution
To work around this bug, do not set the Width property of the DataGrid Boolean column to 1.

BUG: “InvalidOperationException” error message occurs when you consume a Web Service with an Out parameter

Symptoms
You can use Visual C# .NET to create a Web Service that has a Web Service method with an Out parameter. The Out parameter may appear before the In parameter or the Ref parameter. You must specify the SoapRpcMethodAttribute to the Web Service method to preserve the order of the parameters. The problem occurs when you subsequently use this Web service that you created in Visual C# .NET in a Visual Basic .NET application. You may receive the following error message when you call the Web Service method.

An unhandled exception of type ‘System.InvalidOperationException’ occurred in system.xml.dll
Additional information: There was an error generating the XML document.

Resolution
If the Web Service method has an Out parameter, and you generate the proxy by using Visual Basic .NET, then the Out parameter is generated as a ByRef parameter. This occurs because Visual Basic .NET does not support Out parameters. The reflection code cannot differentiate between a real ByRef parameter and a ByRef parameter that corresponds to an Out parameter. In the proxy class, the actual call to the Web service is completed by using the Invoke method. In the Invoke method call, the Out parameter is missing. However, the generated serializer expects the parameter. Therefore, you receive the error.

BUG: “InteropServices.COMException” error message occurs when you pass ByRef Parameters by using late binding

Symptoms
When you call a COM component in Visual Basic .NET, and you use late binding, you may receive the following error message:

An unhandled exception of type ‘System.Runtime.InteropServices.COMException’ occurred in microsoft.visualbasic.dll. Additional information: Type mismatch.This behavior occurs when all the following conditions are true: The method that is called is a Public method in the COM component. The method takes a ByRef parameter of type Object.You use late binding to call the COM component.
Resolution
When you run an application, the .NET Framework late binding mechanism tries to pass the ByRef parameters to the COM component as objects. The COM component expects the parameters to be of the type IDispatch. The .NET Framework raises a type mismatch exception. This occurs because the .NET Framework cannot convert the uninitialized objects to the IDispatch type. The early binding signature of the method in the COM component follows:

[id(0x60030000)]HRESULT MyFunc([in, out] IDispatch** var1);