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 1116101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:15:11+00:00 2026-05-17T03:15:11+00:00

I have a function that gets a string passed to it. When testing the

  • 0

I have a function that gets a string passed to it. When testing the function, I’m getting a null reference exception on the string parameter that gets passed to it, even though the string is not null, I don’t understand why I’m getting this error. I have a screen shot below

alt text

I used a dummy value to verify both the string parameter in the SelectSingleNode function and the newValue string parameter being passed to my function and they both contain values, so I don’t understand why it’s throwing a null reference exception. Just for clarity, the purpose of the function is to write values back to the nodes of an XML file.

UPDATE

Sorry for not posting code

Private Sub setValue(ByVal nodeToMod As String, ByVal newValue As String)
        ''Test writing to xml config file
        Dim dummy As String = "Config/" & nodeToMod
        Dim xmlDoc As New XmlDocument
        Using fs As FileStream = New FileStream(HttpContext.Current.Server.MapPath("~/XML_Config/Config.xml"), FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)
            xmlDoc.Load(fs)
            Dim foo As XmlNode = xmlDoc.SelectSingleNode(dummy)
            Console.WriteLine(foo.InnerXml)
            fs.Seek(0, SeekOrigin.Begin)
            fs.SetLength(0)
            xmlDoc.Save(fs)
        End Using
    End Sub

And here is the XML file I’m working with

<?xml version="1.0" encoding="utf-8"?>
<Config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Username>john.doe@email.com</Username>
  <Password>Password1</Password>
  <ProductType>MyProduct</ProductType>
  <DirectoryEntryPath>LDAP://myDomain</DirectoryEntryPath>
  <SMTPDefaultOnly>True</SMTPDefaultOnly>
  <Logo>myLogo.gif</Logo>
</Config>

Yes, the SlectSingleNode function is not returning a value. I just started working with XPath, this seemed to have worked when I was using last week. I’m not sure why it has stopped working now.

UPDATE2:

Got it, stupid mistake. I had nodeToMod being passed as “UserName” instead of “Username” in the Set method

        Set(ByVal value As String)
            setValue("UserName", value.ToString)
            _userName = value
        End Set
  • 1 1 Answer
  • 3 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-05-17T03:15:12+00:00Added an answer on May 17, 2026 at 3:15 am

    The null reference that is being complained about is the result of the call to SelectSingleNode. That is, when the xpath formed by concatenating /Config/ and the contents of nodeToMod is evaluated against the document, no node matches. So you get null, and attempting to set the InnerText of null gives the exception.

    We would really need to see nodeToMod and the xml file itself to help further. Also, please post code rather than screenshots!

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

Sidebar

Related Questions

I have a function that gets a class passed to it as a parameter.
In my Java code I have function that gets file from the client in
Here's a brief rundown of my issue: I have a JavaScript function that gets
I have this function in jQuery that gets data from a page with POST,
I have a function that sending a code gets a description through various formatings,
I have a function that takes an input string and then runs the string
I am a newbie. I have tried to write a template function that gets
I have a function called CreateCriteriaExpression that takes a json string and creates a
Inside my Controller i have function that runs after user clicks on item, which
So I have function that formats a date to coerce to given enum DateType{CURRENT,

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.