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

Error message when you use CommandBuilder: “An unhandled exception of type ‘System.NullReferenceException’ occurred”

Symptoms
If you use the CommandBuilder object to explicitly get commands for the DataAdapter object as follows:

da.InsertCommand = cb.GetInsertCommand and then run the following Visual Basic .NET code

cb.DataAdapter = Nothing or the following Visual C# .NET code

cb.DataAdapter = null; the commands that you add to the DataAdapter are deleted, and you receive the following error message:

An unhandled exception of type ‘System.NullReferenceException’ occurred in app_name.exe
Additional information: Object reference not set to an instance of an object.
Resolution
CommandBuilder deletes the commands that it generates when it is disassociated from a DataAdapter. CommandBuilder and DataAdapter are linked; when they are unlinked or disassociated, the commands are nulled. This problem does not affect commands that you build from the beginning (from scratch).

BUG: You receive an error message when you serialize a DBConcurrencyException object in ADO.NET 1.0

Symptoms
When you serialize a DBConcurrencyException object, the value of the Row property in the serialized version of the object is set to a null value and an exception occurs:

An unhandled exception of type ‘System.NullReferenceException’ occurred in app_name.exe
Additional information: Object reference not set to an instance of an object.
Resolution
Serialization support is not provided for DataRows in this version of Microsoft Visual Studio .NET.

BUG: Various errors may occur when you try to call managed code from unmanaged code in Visual C++ .NET 2003

Symptoms
You have a Microsoft Visual C++ .NET 2003 application that uses multiple application domains. When you try to call managed code from unmanaged code in a DLL that has already been loaded in another application domain, you may receive the following error message:

An unhandled exception of type ‘System.NullReferenceException’ occurred in mscorlib.dll
Additional information: Object reference not set to an instance of an object.Note In some scenarios, you may receive one of the following error messages:

DllNotFoundException

Illegal Instruction
Resolution
You may notice this problem if your application contains unmanaged code and uses multiple application domains.
For example, if you have an application that uses multiple application domains that use a set of DLLs, you can successfully load and use these DLLs in the first application domain. However, when you try to call the managed code in one of these DLLs from unmanaged code in a different (second) application domain, the behavior that is mentioned in the “Symptoms” section of this article occurs. The application does not load the managed code in the second application domain because the code has already been loaded in another application domain that is in the same process.

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: “System.NullReferenceException” exception while using the vector<bool> class

Symptoms
This article discusses a code bug in the vector file that causesa”System.NullReferenceException” exception and discusses how to resolve this bug.
Resolution
When you call the pop_back method of the vector<bool> template class to delete the last element that is stored in a vector<bool> template class object, you receive the following error message:

An unhandled exception of type ‘System.NullReferenceException’ occurred in ApplicationName
Additional information: Object reference not set to an instance of an object.Note ApplicationName is a placeholder for the executable (.exe) file name of your program.