Object instance not set to an instance of an object error in Asp.Net
I am getting this error every now in then in my ASP.Net web application and cannot understand how. The stack trace leads me to this code and the line is one or other of the calls to the Add method of the HashTable. The code is in a module and the Hash Table is declared as a private variable in that module.
I have added the Debug.Asserts but so far these have only pushed the line number of the error further down to another line where the Add method is called. I am not overriding the Hashtable 's Add method in a derived class. The parameters beginning "gstr" are string constants instantiated in another module.
How can it get past one call to the Add method (which means _hshBaseTables cannot be Null) and then come up with this exception?
<System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)> _
Friend Module modFieldAliases
#Region "Private Data"
'Tables created by InitFieldAliasHashTable and destroyed by calling UnInitFieldAliasHashTable
'private variable to hold lookup table for field aliases.
Private _hshFieldAliases As System.Collections.Hashtable 'use this to obtain underlying field information given the field alias
Private _hshTableAliases As System.Collections.Hashtable 'use this to obtain the base table and column given table alias
Private _hshBaseTables As System.Collections.Hashtable 'use this to obtain table alias from base table
Private _hshBaseColumns As System.Collections.Hashtable 'use this to obtain field alias from base table and column pair
...
If _hshBaseTables IsNot Nothing Then
_hshBaseTables = System.Collections.Specialized.CollectionsUtil.CreateCaseInsensitiveHashtable(50)
Debug.Assert(_hshBaseTables IsNot Nothing)
_hshBaseTables.Add("Alias", gstrALIAS)
Debug.Assert(_hshBaseTables IsNot Nothing)
_hshBaseTables.Add("BlobData", gstrBLOBDATA)
Debug.Assert(_hshBaseTables IsNot Nothing)
_hshBaseTables.Add("ContactLink", gstrCONTACTLINK)
Debug.Assert(_hshBaseTables IsNot Nothing)
_hshBaseTables.Add("CustomForms", gstrCUSTOMFORMS)...
Here is the stack trace:
at modFieldAliases.InitFieldAliasHashTable() in C:\Ajexus 4.59\CriteriaSet\FieldAliases.vb:line 2701
at Ajexus.CriteriaSet._initialize() in C:\Ajexus 4.59\CriteriaSet\CriteriaSet.vb:line 41
at Ajexus.CriteriaSet..ctor() in C:\Ajexus 4.59\CriteriaSet\CriteriaSet.vb:line 46
at Model.GetData(String method, Dictionary`2 data) in C:\Ajexus 4.59\Ajexus MVP Framework\Model.vb:line 424
at Ajexus.Framework.ReportsHelper.GetUserCriteriaListContents(String strFieldAlias, CriteriaSet csPredefinedReportCriteria, CriteriaSet csReportCriteria) in C:\Ajexus 4.59\Ajexus MVP Framework\ReportsHelper.vb:line 560
at Ajexus.Framework.Presenters.Summary2ViewPresenter._fillUserCriteriaList(CriteriaSet csPredefinedReport, String strFieldAlias, String strFieldLabel, String strDisplayMember, String strValueMember) in C:\Ajexus 4.59\Ajexus MVP Framework\Presenters\Summary2.aspx.presenter.vb:line 173
at Ajexus.Framework.Presenters.Summary2ViewPresenter.OnFillUserCriteriaFieldList(Object sender, AjexusFieldEventArgs e) in C:\Ajexus 4.59\Ajexus MVP Framework\Presenters\Summary2.aspx.presenter.vb:line 836
at Ajexus.Web.Views.Summary2.fvwUserCriteria_PreRender(Object sender, EventArgs e) in C:\Ajexus 4.59\AjexusWeb\Summary2.aspx.vb:line 80
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Additional Information The _hshBaseTables variable is Nothing when the exception is caught and the stack trace usually indicates a different line than previously. But it is always after the check for Nothing and after nearly identical lines of code where the exception has not been thrown. This suggests doesn't it that it must have been set to Nothing by another thread in between this thread's calls to the Add method? hshBaseTables is a private variable in a Friend Module which is included also in another component used by my application.