LeeHenry
asked on
Object reference not set to an instance of an object.
I created a master page, and put 3 TreeView Controls on the page. I binded each of the treeView controls to 3 XmlDataSources. I keep getting the below error message, but I don't have any idea what is going on. I tried to trap the error in the code behind, but the error is not getting thrown in the application. I believe from the stack trace it has something to do with the binding of the xml data source? Any suggestions would be greatly appreciated.
Description: 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.
Exception Details: System.NullReferenceExcept ion: Object reference not set to an instance of an object.
Source Error:
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.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
System.Xml.XmlLoader.Load( XmlDocumen t doc, XmlReader reader, Boolean preserveWhitespace) +39
System.Xml.XmlDocument.Loa d(XmlReade r reader) +159
System.Web.UI.WebControls. XmlDataSou rce.Popula teXmlDocum ent(XmlDoc ument document, CacheDependency& dataCacheDependency, CacheDependency& transformCacheDependency) +388
System.Web.UI.WebControls. XmlDataSou rce.GetXml Document() +204
System.Web.UI.WebControls. XmlHierarc hicalDataS ourceView. Select() +42
System.Web.UI.WebControls. TreeView.D ataBindNod e(TreeNode node) +479
System.Web.UI.WebControls. TreeView.P erformData Binding() +136
System.Web.UI.WebControls. Hierarchic alDataBoun dControl.P erformSele ct() +93
System.Web.UI.WebControls. BaseDataBo undControl .DataBind( ) +99
System.Web.UI.WebControls. TreeView.D ataBind() +24
System.Web.UI.WebControls. BaseDataBo undControl .EnsureDat aBound() +92
System.Web.UI.WebControls. BaseDataBo undControl .OnPreRend er(EventAr gs e) +33
System.Web.UI.WebControls. TreeView.O nPreRender (EventArgs e) +183
System.Web.UI.Control.PreR enderRecur siveIntern al() +148
System.Web.UI.Control.PreR enderRecur siveIntern al() +233
System.Web.UI.Control.PreR enderRecur siveIntern al() +233
System.Web.UI.Control.PreR enderRecur siveIntern al() +233
System.Web.UI.Page.Process RequestMai n(Boolean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt) +4440
Description: 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.
Exception Details: System.NullReferenceExcept
Source Error:
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.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
System.Xml.XmlLoader.Load(
System.Xml.XmlDocument.Loa
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.Control.PreR
System.Web.UI.Control.PreR
System.Web.UI.Control.PreR
System.Web.UI.Control.PreR
System.Web.UI.Page.Process
may be you can run it in debug mode to see the error details
can you post the code how you use Load for XmlDocument?
ASKER
When I run it in debug mode, i can't trap the error, because it is not being thrown in any of the code behind files.
aki4u,
private void Refresh_XML_Data_Source(Xm
{
myXmlDataSource.EnableCach
myXmlDataSource.Data = myXmlData;
}
and... can make a break point to see the "myXmlDataSource" value
>>myXmlDataSource.EnableCa ching = false; <-- in this line
>>myXmlDataSource.EnableCa
that is probably because myXmlDataSource is null.
try this:
private void Refresh_XML_Data_Source(Xm lDataSourc e myXmlDataSource, string myXmlData)
{
if (!(XmlDataSource == null))
{
myXmlDataSource.EnableCach ing = false;
myXmlDataSource.Data = myXmlData;
}
}
try this:
private void Refresh_XML_Data_Source(Xm
{
if (!(XmlDataSource == null))
{
myXmlDataSource.EnableCach
myXmlDataSource.Data = myXmlData;
}
}
ASKER
aki4u,
This didn't fix the problem. I'm getting the error after the page unloads...
??
This didn't fix the problem. I'm getting the error after the page unloads...
??
same error? if not, can you post the error description?
ASKER
yes.. same error..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
figured it out.. The problem was on the Page Init when I loaded the master pages dynamically, I was doing a postback Check, and when the page unloaded it was crashing because the master page wasn't assigned. I removed the postback check, and it works.
Thanks for the suggestions..
Thanks for the suggestions..