.NET Questions and Solutions

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 ‘object’

BUG: “Object variable or With block variable not set” error message when you access a public object variable

Symptoms
When you set a public object variable of a Microsoft Component Object Model (COM) component in Microsoft Visual Basic .NET or in Microsoft Visual Basic 2005, you may receive the following error message:

An unhandled exception of type ‘System.Runtime.InteropServices.COMException’ occurred in microsoft.visualbasic.dll
Additional information: Object variable or With block variable not set
Resolution
This behavior can occur if all the following conditions are true: You define a public variable in the COM component.The variable is of the Object type.You reference this COM component by using late binding in Visual Basic .NET or in Visual Basic 2005. When you access the public object by using late binding, Visual Basic .NET or Visual Basic 2005 does not correctly set the BindingFlags enumeration.
The BindingFlags enumeration is used to specify the flags that control binding and the way in which the search for members and types is conducted by reflection.

BUG: “Attempt to Access the Method Failed” Error Message When You Use a Reference to the Wrong Microsoft Forms 2.0 Object Library

Symptoms
In a Visual Studio .NET project that contains a reference to the Microsoft Forms 2.0 Object Library, you may receive an error message similar to the following:

System.MethodAccessException: “Attempt to access the method failed.”
Resolution
When you use the Add Reference dialog box to add a reference to the Microsoft Forms 2.0 Object Library, you may notice that two entries appear for Microsoft Forms 2.0 Object Library.Both of these entries refer to the FM20.dll file.
You must select the first Microsoft Forms 2.0 Object Library entry in the list because this is the Primary Interop Assembly (PIA) reference. If you select the second Microsoft Forms 2.0 Object Library entry, your application may not behave as expected.

An unhandled exception of the ‘System.ArgumentException’ type occurs after you rename the columns of a DataSet object

Symptoms
After you rename the columns of a DataTable object in the DataSet, if you try to refer to the columns in case-insensitive manner, you receive the following exception:

An unhandled exception of type ‘System.ArgumentException’ occurred in system.data.dll
Additional information: Column ‘ColumnName’ does not belong to table ‘Tablename’.
Resolution
When you first create a column in a DataTable object of a DataSet, the name is added to two indexes: a case-sensitive index and a case-insensitive index. When you rename the column in a DataTable object, the new name is not added to the case-insensitive index. Therefore, when you rename a DataTable column, the ColumnName becomes case-sensitive.

ACC2000: How to Reference Classes That Exist in Multiple Libraries

Symptoms
If your Microsoft Access database contains a reference to multiple librarydatabases, type libraries, or object libraries, it is possible for the sameclass name to exist in more than one referenced file. If you want todeclare a variable of that type, you must explicitly state which referencecontains the class that you want to use. This article shows you how tospecify a particular reference file in code.
Resolution
Suppose that your Microsoft Access database contains two references: onereference to a library database called MyDatabase, which contains a classcalled RecordSet, and another reference to Microsoft DAO 3.6 ObjectLibrary, which also contains a class called RecordSet. To dimension a variable of type RecordSet from the MyDatabase reference, you must use the following syntax:

Dim rs as MyDatabase.RecordSet If you do not explicitly declare the reference name when you dimension thevariable, whichever reference appears first in the References dialogbox is automatically assumed. If the wrong reference is assumed, you mayencounter error messages when you try to use the properties and methods ofthe declared object.
You can use the Microsoft Access Object Browser to determine the referencename. To use the Object Browser, open any module in Design view, and thenclick Object Browser on the View menu (or press the F2 key). The name that appears in the Project/Library box of the Object Browser is the name of that reference.

ACC2000: “Object Invalid or No Longer Set” Error with CurrentDb

Symptoms
When you refer to properties and methods belonging to objects created withthe CurrentDb function, you may receive the following error message:

Object invalid or no longer set.
Resolution
When you set an object variable, such as a TableDef object, which requiresa reference to a database object, your code refers directly to theCurrentDb function instead of referring to a database object variable thatyou set with the CurrentDb function.

A memory leak may occur when you use data binding in Windows Presentation Foundation

Symptoms
When you use data binding in Microsoft Windows Presentation Foundation (WPF), a memory leak may occur.
Resolution
This issue occurs if the following conditions are true:A data-binding path refers to property P of object X.Object X contains a direct reference or an indirect reference to the target of the data-binding operation.Property P is accessed through a PropertyDescriptor object instead of a DependencyProperty objector a PropertyInfo object.