任何人都可以解释这个例外吗?
Object reference not set to an instance of an object.
描述:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
异常详细信息:
System.NullReferenceException: Object reference not set to an instance of an object.
来源错误:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
堆栈追踪:
[NullReferenceException: Object reference not set to an instance of an object.]
System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) +24
System.Xml.XmlDocument.Load(XmlReader reader) +108
System.Web.UI.WebControls.XmlDataSource.PopulateXmlDocument(XmlDocument document, CacheDependency& dataCacheDependency, CacheDependency& transformCacheDependency) +342
System.Web.UI.WebControls.XmlDataSource.GetXmlDocument() +253
System.Web.UI.WebControls.XmlHierarchicalDataSourceView.Select() +51
System.Web.UI.WebControls.Menu.DataBindItem(MenuItem item) +326
System.Web.UI.WebControls.Menu.PerformDataBinding() +99
System.Web.UI.WebControls.HierarchicalDataBoundControl.PerformSelect() +126
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +125
System.Web.UI.WebControls.Menu.DataBind() +29
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +104
System.Web.UI.WebControls.Menu.EnsureDataBound() +70
System.Web.UI.WebControls.BaseDataBoundControl.OnPreRender(EventArgs e) +43
System.Web.UI.WebControls.Menu.OnPreRender(EventArgs e, Boolean registerScript) +89
System.Web.UI.WebControls.Menu.OnPreRender(EventArgs e) +63
System.Web.UI.Control.PreRenderRecursiveInternal() +200
System.Web.UI.Control.PreRenderRecursiveInternal() +322
System.Web.UI.Control.PreRenderRecursiveInternal() +322
System.Web.UI.Control.PreRenderRecursiveInternal() +322
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4837
答案 0 :(得分:1)
没有看到你的代码就很难说,但是通过堆栈跟踪的外观,我会猜测并说你有一个绑定到XmlDataSource
的TreeView / Menu。
显然在数据绑定过程中出现了问题,但是再次看不到填充XmlDataSource
的代码,它几乎无法帮助你进一步帮助你。
答案 1 :(得分:1)
从XmlReader
传递到XmlDocument.Load
的{{1}}实例为空,这意味着XmlLoader.Load
将空读取器传递给XmlDataSource.PopulateXmlDocument
,这发生在XmlDocument.Load
1}}返回null。
发生这种情况的唯一代码路径要求XmlDataSource.GetReader
为空或空且 XmlDataSource.DataFile
为空,空或仅为空白字符的成本。