Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Object reference not set to an instance of an object.

Posted on 2006-04-10
10
Medium Priority
?
585 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:LeeHenry
  • 4
  • 4
  • 2
10 Comments
 
LVL 18

Expert Comment

by:Elvio Lujan
ID: 16418755
may be you can run it in debug mode to see the error details
0
 
LVL 10

Expert Comment

by:aki4u
ID: 16418886
can you post the code how you use Load for XmlDocument?
0
 
LVL 6

Author Comment

by:LeeHenry
ID: 16419481

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;
    }
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:Elvio Lujan
ID: 16419501
and... can make a break point to see the "myXmlDataSource" value
>>myXmlDataSource.EnableCaching = false; <-- in this line
0
 
LVL 10

Expert Comment

by:aki4u
ID: 16419597
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;
                  }
            }
0
 
LVL 6

Author Comment

by:LeeHenry
ID: 16419822
aki4u,

This didn't fix the problem. I'm getting the error after the page unloads...
??
0
 
LVL 10

Expert Comment

by:aki4u
ID: 16419996
same error? if not, can you post the error description?
0
 
LVL 6

Author Comment

by:LeeHenry
ID: 16420010
yes.. same error..
0
 
LVL 10

Accepted Solution

by:
aki4u earned 1500 total points
ID: 16420241
can you get the line where it fails?
same error means that you some of your objects are null and you are trying to use them.
try doing the same as I posted...e.g

if (!(object== null))
{
//your code here
}
0
 
LVL 6

Author Comment

by:LeeHenry
ID: 16421385
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..
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month15 days, 17 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question