.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 for the ‘object reference’ Category

BUG: Reference to Deferred Object in Stored Procedure Will Not Show in Sp_depends

Symptoms
The output of sp_depends for an object created with dependencies on objects whose name resolution is deferred will not be correct. For an example of this, see the MORE INFORMATION section of this article.
Resolution
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

BUG: FIX: VBScript Can Corrupt Data Stored in Scripting Dictionary Object

Symptoms
If you assign Request.Form or QueryString items in a Scripting Dictionary object cached in Session scope, you will corrupt your data. Corrupted data will manifest either as empty fields (that is, blank individual dictionary items) or as items containing garbage text.
Resolution
VBScript does not use IDispatch to fetch the Response object’s default property. This results in an object reference being assigned to an Item in the Dictionary (even when the assignment in your script does not use the Set statement). When this object reference is then cached with Session scope, a related bug in Active Server Pages (ASP) doesn’t catch and block the object reference (see 216825?(http://support.microsoft.com/kb/216825/EN-US/) “BUG: Assignment of Multi-valued Objects in Request Object Causes Corruption in Scripting Dictionary” for details).

BUG: Internal Compiler Error C1001 When You Call __assume()

Symptoms
When a function that expects STL::string as a reference is passed as an input argument to the __assume function, you may get the following error message:

repro.cpp(18): fatal error C1001: INTERNAL COMPILER ERROR
(compiler file ‘E:\8447\vc98\p2\src\P2\main.c’, line 494)
Please choose the Technical Support command on the Visual C++Help menu, or open the Technical Support help file for more information.Please refer to the “More Information” section for the sample code that reproduces the problem.
Resolution
Use one of the following two methods to work around this problem:Construct a temporary STL::string object and pass this object as a reference to the function (see workaround 1 in the sample code).Introduce a temporary variable to store the return value of the function, which expects STL::string as reference (see workaround 2 in the sample code).

BUG: Error message when you try to pass a Collection object from Visual Basic 6.0 components to Visual Basic 2005 or to Visual Basic .NET: “System.InvalidCastException”

Symptoms
When you try to pass a Collection object fromMicrosoft Visual Basic 6.0 components to Microsoft Visual Basic 2005 or to Microsoft Visual Basic .NET, you may receive an error message. In Microsoft Visual Studio 2005, you receive the following error message:

An unhandled exception of type ‘System.InvalidCastException’ occurred in ApplicationName.exe
Additional information: Unable to cast object of type ‘Microsoft.VisualBasic.Collection’ to type ‘VBA.Collection’.In Microsoft Visual Studio .NET, you receive the following error message:

An unhandled exception of type ‘System.InvalidCastException’ occurred in ApplicationName.exe
Additional information: Specified cast is not valid.If you examine the type of the collection object that Visual Basic 2005 or Visual Basic .NET expects, you find that Visual Basic 2005 or Visual Basic .NET expects the VBA.Collection type instead of the Microsoft.VisualBasic.Collection type. If you change your code to pass a collection object of the VBA.Collection type, you receive the following error message on the line of code where you try to create a new instance of the VBA.Collection class:

An unhandled exception of type ‘System.Runtime.InteropServices.COMException’ occurred in ApplicationName.exe
Additional information: COM object with CLSID {A4C4671C-499F-101B-BB78-00AA00383CBB} is either not valid or not registered.This problem also occurs in other Microsoft .NET Framework-supported languages such as Microsoft Visual C# 2005 and earlier versions of .NET Framework-supported Microsoft Visual C#.
Resolution
The InvalidCastException error occurs because the Microsoft.VisualBasic.Collection type is incompatible with the VBA.Collection type. The COMException error occurs because only a Visual Basic 6.0 application can create an instance of the VBA.Collection class. You cannot create an instance of the VBA.Collection class outside a Visual Basic 6.0 application.

BUG: Cannot Reference Excel 8.0 Object Library from VB 4.0x

Symptoms
Microsoft Visual Basic 4.0x does not allow addition of the Microsoft Excel8.0 Object Library via Tools/References when the Microsoft Excel 5.0 ObjectLibrary is listed there.
Resolution
When adding a new version of an object (or type) library to itsTools/Reference list, Microsoft Visual Basic 4.0x, in spite of thedistinctly different version numbers of the old and new object libraries,insists, via an internal string-comparison routine, that the new library’sLocale/Country ID (LCID) be identical to the old library’s LCID. Becausethe Microsoft Excel 5.0 Object Library has an LCID of 9 (English) and theMicrosoft Excel 8.0 Object Library has an LCID of 0 (Default Language),this test fails; Microsoft Visual Basic 4.0x then displays the error:

“Object library’s language setting incompatible with current project”and does not add the new library to the Tools/Reference list.

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.