Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8894131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:25:05+00:00 2026-06-14T23:25:05+00:00

Am developing a web-application in ASP.NET (C#) and following code snippet is part of

  • 0

Am developing a web-application in ASP.NET (C#) and following code snippet is part of a function:

string[] paramList = new string[2];
string[] paramValList = new string[2];

XDocument doc = XDocument.Parse(paramXML);
var oParamCollection = from parameters in doc.Descendants("myfunction")
          select new
          {
          Name = parameters.Attribute("myParam").Value,
          Value = parameters.Attribute("myParamValue").Value
          };

int i=0;
foreach (var oParam in oParamCollection)
{
    string name = oParam.Name.Trim();
    string value = oParam.Value.Trim();

    paramList[i] = oParam.Name.Trim();
    paramValList[i++] = oParam.Value.Trim();

    if (i >= 2)
    break;
}

Following is the value of paramXML variable (parameter) being used at the 3 code-line:

<root><myfunction myparam=" DeliveryDate" myparamvalue="2012-07-01" ></myfunction></root>

Now the issue is that when I open my web-application in Chrome or Firefox, there is not error but when I use it in IE 9 (in same state and with same development environment), I get System.NullReferenceException: Object reference not set to an instance of an object at the start of foreach loop. While debugging, I checked the value of oParamCollection in QuickWatch while using in Chrome or FireFox and I get the count as 1 but when I checked the value while using the application in IE 9, the count gives the exception. Am so much confused. Have spent quite sometime on internet searching for this problem but no pointer till now. SO is my last hope. Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:25:06+00:00Added an answer on June 14, 2026 at 11:25 pm

    After lot of debugging, finally I have found the solution. The problem is surely in the code snippet (due to my silly mistake) mentioned in the question. The problematic code is as follows:

                var oParams = from parameters in l_oXDoc.Descendants("myfunction")
                              select new
                              {
                                  //Name = (string) parameters.Attribute("myParam"),
                                  //Value = (string) parameters.Attribute("myParamValue")
                                  Name = parameters.Attribute("myParam").Value,
                                  Value = parameters.Attribute("myParamValue").Value
                              };
    

    The issue was that the XML string had the attribute names myParam and myParamValue in lowercase whereas here in code I was checking in camel case. The problem got resolved the moment I changed it to ‘myparam’ and ‘myparamvalue’ into lower case in my code. My rectified code is as follows:

                var oParams = from parameters in l_oXDoc.Descendants("myfunction")
                              select new
                              {
                                  Name = parameters.Attribute("myparam").Value,
                                  Value = parameters.Attribute("myparamvalue").Value
                              };
    

    But my doubt still remains the same, why it happens only for IE and not while using Chrome or FF? I request respectable members of SO to try this and check it on their own.

    I would like to thank Jon Skeet for giving me a pointer (+1 for you). @Jon, it my case, the Value property works for attribute. If you have any reference to cases where the Value may not work, please do share it with me. Thank you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an ASP.NET web application and I use the following connection string
I am new to MVC. I am developing an web application in asp.net MVC.
For the web application (ASP.NET MVC) I'm currently developing, we have the following architecture
I'm developing a web application using ASP .NET MVC 1.0 and jQuery (including the
I am currently developing a web application in ASP.NET Framework 4 and I am
I am developing a mobile web application in asp.net. I have a button in
I am developing an ASP.Net MVC 3 Web application using Razor Views. I have
I am developing an ASP.Net VB Web Application The application contains a GridView which
I am developing an ASP.NET web application that incorporates google maps. I have an
I am developing an asp.net web application. I need to use java script to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.