对象实例未设置为 Asp.Net 中对象错误的实例
我现在在我的 ASP.Net Web 应用程序中遇到这个错误并且无法理解。堆栈跟踪将我引向此代码,并且该行是对 HashTable 的 Add 方法的一个或其他调用。代码位于模块中,哈希表在该模块中声明为私有变量。
我已经添加了 Debug.Asserts 但到目前为止,这些只是将错误的行号进一步向下推到调用 Add 方法的另一行。我没有在派生类中覆盖 Hashtable 的 Add 方法。以“gstr”开头的参数是在另一个模块中实例化的字符串常量。
它怎么能通过对 Add 方法的一次调用(这意味着 _hshBaseTables 不能为 Null)然后提出这个异常?
<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)...
这是堆栈跟踪:
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)
附加信息 _hshBaseTables 变量在异常被捕获并且堆栈跟踪通常指示与以前不同的行时为 Nothing。但它总是在检查 Nothing 之后以及几乎相同的代码行之后没有引发异常。这是否表明它必须在该线程调用 Add 方法之间被另一个线程设置为 Nothing ?hshBaseTables 是朋友模块中的私有变量,它也包含在我的应用程序使用的另一个组件中。