Link to home
Start Free TrialLog in
Avatar of LeeHenry
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.NullReferenceException: 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(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) +39
   System.Xml.XmlDocument.Load(XmlReader reader) +159
   System.Web.UI.WebControls.XmlDataSource.PopulateXmlDocument(XmlDocument document, CacheDependency& dataCacheDependency, CacheDependency& transformCacheDependency) +388
   System.Web.UI.WebControls.XmlDataSource.GetXmlDocument() +204
   System.Web.UI.WebControls.XmlHierarchicalDataSourceView.Select() +42
   System.Web.UI.WebControls.TreeView.DataBindNode(TreeNode node) +479
   System.Web.UI.WebControls.TreeView.PerformDataBinding() +136
   System.Web.UI.WebControls.HierarchicalDataBoundControl.PerformSelect() +93
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +99
   System.Web.UI.WebControls.TreeView.DataBind() +24
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +92
   System.Web.UI.WebControls.BaseDataBoundControl.OnPreRender(EventArgs e) +33
   System.Web.UI.WebControls.TreeView.OnPreRender(EventArgs e) +183
   System.Web.UI.Control.PreRenderRecursiveInternal() +148
   System.Web.UI.Control.PreRenderRecursiveInternal() +233
   System.Web.UI.Control.PreRenderRecursiveInternal() +233
   System.Web.UI.Control.PreRenderRecursiveInternal() +233
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4440
Avatar of Elvio Lujan
Elvio Lujan
Flag of Argentina image

may be you can run it in debug mode to see the error details
Avatar of aki4u
aki4u

can you post the code how you use Load for XmlDocument?
Avatar of LeeHenry

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(XmlDataSource myXmlDataSource, string myXmlData)
    {
        myXmlDataSource.EnableCaching = false;
        myXmlDataSource.Data = myXmlData;
    }
and... can make a break point to see the "myXmlDataSource" value
>>myXmlDataSource.EnableCaching = false; <-- in this line
that is probably because myXmlDataSource is null.


try this:

            private void Refresh_XML_Data_Source(XmlDataSource myXmlDataSource, string myXmlData)
            {
                  if (!(XmlDataSource == null))
                  {
                        myXmlDataSource.EnableCaching = false;
                        myXmlDataSource.Data = myXmlData;
                  }
            }
aki4u,

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?
yes.. same error..
ASKER CERTIFIED SOLUTION
Avatar of aki4u
aki4u

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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..