.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 reference not set to an instance’

FIX: A Windows Forms application that uses ActiveX controls may crash, and a null reference exception occurs after you install the .NET Framework 2.0 Service Pack 1

Symptoms
After you install the Microsoft .NET Framework 2.0 Service Pack 1, a Windows Forms application that uses Microsoft ActiveX controls may crash. When this problem occurs, a null reference exception occurs. Additionally, the following call stack is generated in the Windows Forms application:

System.NullReferenceException: Object reference not set to an instance of an object.at System.Windows.Forms.AxHost.OleInterfaces.AttemptStopEvents(Object trash)at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)
Resolution
Hotfix informationA supported hotfix is now available from Microsoft. However, it is intended to correct only the problem that is described in this article. Apply it only to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next .NET Framework 2.0 service pack that contains this hotfix.
To resolve this problem immediately, contact Microsoft Customer Support Services to obtain the hotfix. For a complete list of Microsoft Customer Support Services telephone numbers and information about support costs, visit the following Microsoft Web site:
http://support.microsoft.com/contactus/?ws=support(http://support.microsoft.com/contactus/?ws=support)Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question.Prerequisites To apply this hotfix, you must have the .NET Framework 2.0 Service Pack 1 installed. Restart requirementYou do not have to restart the computer after you apply this hotfix.Hotfix replacement informationThis hotfix does not replace any other hotfixes.File information The English version of this hotfix has the file attributes (or later file attributes) that are listed in the following table. The dates and times for these files are listed in Coordinated Universal Time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time item in Control Panel.
Collapse this tableExpand this table
File nameFile versionFile sizeDateTimePlatformSystem.windows.forms.dll2.0.50727.18195,173,24814-3-200803:40×86

FIX: A System.NullReferenceException exception occurs when you deploy a composite database project in Microsoft Visual Studio Team System 2008 Database Edition GDR

Symptoms
Consider the following scenario in Microsoft Visual Studio Team System 2008 Database Edition GDR: You have a database project that includes tables.You have another database project that includes constraints for the tables in the same solution and you add a reference to the database project that includes tables.You connect both projects to the same target database on a server.Then, you deploy the projects to the database.In this scenario, you receive a System.NullReferenceException exception and then the Visual Studio IDE crashes. If you debug this exception, you receive the following error message:

System.NullReferenceException: Object reference not set to an instance of an object.
Resolution
To resolve this problem, upgrade to Microsoft Visual Studio Team System 2008 Database Edition GDR R2. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
970479?(http://support.microsoft.com/kb/970479/) List of fixed issues in the Microsoft Visual Studio Team System 2008 Database Edition GDR R2
Note Microsoft Visual Studio Team System 2008 Database Edition GDR R2 replaces Microsoft Visual Studio Team System 2008 Database Edition GDR.

FIX: A dump file may be generated in the Reporting Services Logfiles folder and you may receive an error message when you try to render a report in SQL Server 2008 Reporting Services

Symptoms
Consider the following scenario. In Microsoft SQL Server 2008 Reporting Services, you create a report. The report contains a Tablix data region item, a Subreport item, or a Chart item. The item has the NoRowsMessage property set, and there are no rows in the data region. Or, the report contains a Subreport item that displays error messages. The text box that is generated to display the error messages is split across a report page. You try to render the report. In this scenario, a dump file may be generated in the Reporting Services Logfiles folder. Additionally, you may receive an error message that resembles the following:

Assert in function = Microsoft.ReportingServices.Rendering.HPBProcessing.Paragraph.get_SpaceBefore file =line = 0 expression = Unhandled managed exception: Type = System.NullReferenceException, Message = Object reference not set to an instance of an object.
Resolution
The fix for this issue was first released in Cumulative Update 1. For more information about how to obtain this cumulative update package for SQL Server 2008, click the following article number to view the article in the Microsoft Knowledge Base:
956717?(http://support.microsoft.com/kb/956717/) Cumulative update package 1 for SQL Server 2008Note Because the builds are cumulative, each new fix release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2008 fix release. We recommend that you consider applying the most recent fix release that contains this hotfix.For more information, click the following article number to view the article in the Microsoft Knowledge Base:
956909?(http://support.microsoft.com/kb/956909/)The SQL Server 2008 builds that were released after SQL Server 2008 was released

FIX: “Exception caught: Object reference not set to an instance of an object” error message when you compile a large map in BizTalk Server 2004

Symptoms
In Microsoft BizTalk Server 2004, you may receive the following error message when you try to compile a large map:

Exception Caught: Object reference not set to an instance of an object.
Resolution
Service pack informationTo resolve this problem, obtain the latest service pack for Microsoft BizTalk Server 2004. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
888751?(http://support.microsoft.com/kb/888751/) How to obtain the latest BizTalk Server 2004 service pack
Hotfix informationThe English version of this hotfix has the file attributes (or later file attributes) that are listed in the following table. The dates and times for these files are listed in Coordinated Universal Time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel.

DateTimeVersionSizeFile name——————————————————————————————01-Apr-200402:313.0.5267.0676,864Btsxmltools.dll01-Apr-200402:573.0.5267.0274,432Microsoft.biztalk.basefunctoids.dll01-Apr-200402:573.0.5267.045,056Microsoft.biztalk.crossreferencing.dll01-Apr-200402:573.0.5267.040,960Microsoft.biztalk.crossreferencingfunctoids.dll01-Apr-200402:573.0.5267.0249,856Microsoft.biztalk.mapper.dll01-Apr-200402:573.0.5267.01,114,112Microsoft.biztalk.tom.dll
NoteBecause of file dependencies, the most recent hotfix that contains these files may also contain additional files.

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).

Error message when you use a startup script to start the SQL Server PowerShell provider in SQL Server 2008: “Set-Location: Object reference not set to an instance of an object”

Symptoms
Microsoft SQL Server 2008 installs the SQL Server PowerShell (SQLPS) provider as a feature. When you use a startup script to start the SQL Server PowerShell provider separately without using the SQLPS minishell, the SQL Server PowerShell provider does not let you navigate the SQL Server object hierarchy. Instead, you receive the following exception error message:

Set-Location: Object reference not set to an instance of an object.
Resolution
The SQL Server PowerShell provider requires certain global variables to exist. Typically, the SQLPS minishell sets these global variables. However, when you use a startup script to start the SQL Server PowerShell provider, these global variables are not declared.