SQL Server 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’

InterOp interfaces must match Vtable layout for early binding to work

Symptoms
When you call a COM method through InterOp, you may receive the following error message:

An unhandled exception of type System.Exception occurred in ApplicationName.exe
Additional information: Object reference not set to an instance of an object.
Resolution
This problem may occur when the order of the methods declaration in the InterOp interface does not match the order of the Vtable layout of the COM interface (which is determined by their layout in IDL). Because you perform early binding in most cases, the order of the methods is very important in this scenario.

InvalidCastException when you bind DateTimePicker that contains a null value in Visual Basic

Symptoms
When you bind a DateTimePicker control to a data source, you may receive the following error message:

An unhandled exception of type ‘System.InvalidCastException’ occurred in mscorlib.dll
Additional information: Object cannot be cast from DBNull to other types.
Resolution
This behavior occurs if the field that is bound to the DateTimePicker control contains a null value that is represented by the System.DBNull object. The DateTimePicker control does not support the System.DBNull object.

BUG: Unexpected exception when you perform a late bind to call a Component Object Model component that returns a structure

Symptoms
In a Microsoft .NET Framework application, when you perform a late bind to call a Component Object Model (COM) component that returns a structure, you may receive the following exception when you run the application:

An unhandled exception of type ‘System.ArgumentException’ occurred in Mscorlib.dll
Additional information: The method returned a VT_RECORD Variant, which is not supported by Interop.
Resolution
To work around this bug, perform an early bind instead of a late bind while you call the COM component.

BUG: The XmlValidatingReader class does not close the stream when the XML document references a DTD that has errors

Symptoms
When you validate your XML document by using the XmlValidatingReader class with respect to an external document type definition (DTD), and the DTD has an error, the stream that is opened by XmlValidatingReader to load the DTD is not closed. Therefore, when you try to open the DTD with write permissions, you receive the following error message:

An unhandled exception of type ‘System.IO.IOException’ occurred in mscorlib.dll
Additional information: The process cannot access the file “DTDFileName” because it is being used by another process.
Resolution
When you use XmlValidatingReader to validate an XML document with respect to DTD, the .NET Framework internally opens a stream to read the DTD. When the error occurs while validating the XML document, the stream that is used to read the DTD is not closed, and you receive the error message that is listed in the “Symptoms” section.

BUG: Error message when you use the FindString method or the FindStringExact method in Visual Basic .NET or in Visual C# .NET: “System.ArgumentOutOfRangeException”

Symptoms
In Visual Basic .NET or in Visual C# .NET, you can invoke the overloaded two-argument FindString method or the overloaded two-argument FindStringExact method of the ComboBox class or the ListBox class. However, when the startIndex parameter is equal to the index value of the last item of the associated list, you may receive the following error message:

An unhandled exception of type ‘System.ArgumentOutOfRangeException’ occurred in system.windows.forms.dll
Additional information: Specified argument was out of the range of valid values.If you handle this exception in a Try/Catch block, you may receive an error message similar to the following:

Unhandled Exception: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: startIndex
at System.Windows.Forms.ListBox.FindStringExact(String s, Int32 startIndex)
at WindowsApplication1.Form1.Button1_Click(Object sender, EventArgs e) in %Form Path%\Form Name:line 83Note Form Name is a placeholder for the file name of the Form that contains the ComboBox object or the ListBox object that invokes the FindString method or the FindStringExact method. Additionally, %Form Path% is a placeholder for the path of the previously mentioned Form.
Resolution
When you invoke either the two-argument FindString method or the two-argument FindStringExact method, a startIndex parameter is used. This startIndex parameter may be equal to the index value of the last item of the associated list for a ComboBox object or a ListBox object. In such cases, the invoked method is supposed to start searching from the beginning of the list for the string that is passed as the first parameter. However, the invoked method incorrectly begins the search after the last item of the list. Therefore, the list boundary is crossed during the search, and you receive the error message in the “Symptoms” section.

BUG: Call IPropertyPage::GetPageInfo on Stock Property Pages of MsStkPrp.dll Can Give Unhandled Exception

Symptoms
If you call IPropertyPage::GetPageInfo on any of the stock property pages (CLSID_StockColorPage, CLSID_StockFontPage, or CLSID_StockPicturePage) exported from MsStkPrp.dll, you may receive an unhandled exception.
Resolution
Work around this problem by setting the property page site; call IPropertyPage::SetPageSite, and pass a pointer to an implementation of IPropertyPageSite immediately after using the CoCreate function of the property page object or anytime before you call GetPageInfo.