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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:02:32+00:00 2026-06-02T02:02:32+00:00

We are trying to read information from a separate XML document. This is the

  • 0

We are trying to read information from a separate XML document.

This is the code we have:

'load the XMLTest document containing cars.
    Dim xml As XDocument = XDocument.Load("CreditApp.xml")


    Dim SSN As String = txtSSN.Text
    'get all car makes that are red.
    Dim query = From xe In xml.Descendants("SSN")
         Where xe.Element("SSN").Value = SSN
                Select New With {
                    .FName = xe.Element("FName").Value 'Error in code is here
                }

    'loop through query result output results.
    For Each element In query.ToArray
        MessageBox.Show(element.FName)
    Next

We are getting the error:

Object reference not set to an instance of an object.

We are not sure what it is refering too.

  • 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-02T02:02:35+00:00Added an answer on June 2, 2026 at 2:02 am

    When you seed that message it means that you tried to access a member of a variable that currently has the value of Nothing.

    Dim obj As Object = Nothing
    Console.WriteLine(obj.ToString()) ' Null ref on obj access
    

    The value Nothing in VB.Net (similar to C# null) means the object has no value. Attempting to access a member on it is accessing a member on nothing. The runtime can’t satisfy this request and hence throws an exception to let you know about the problem.

    In this particular sample it looks like the most likely cause of the error is the following line

    FName = xe.Element("FName").Value
    

    This code doesn’t do anything to validate that xe.Element("FName") doesn’t return Nothing and hence can lead to an exception when accessing the member Value. To fix this you need to guard against this possibility. The easiest way is to use a helper method

    Public Function GetFNameValueOrEmpty(ByVal elem As XElement) As String
      Dim child = elem.Element("FName")
      If child Is Nothing Then
        Return String.Empty
      Else
        Return child.Value
      End If
    End Function
    

    With this helper you could rewrite the original query as such

    Dim query = From xe In xml.Descendants("SSN")
             Where xe.Element("SSN").Value = SSN
                    Select New With {
                        .FName = GetFNameValueOrEmpty(xe)
                    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read weather information from the Google Weather API. My Code looks
Trying to read in some information from the google maps api into my application
I'm trying to read some information from a text file and put in a
I am trying to read product information from some text files. In my text
I'm trying to read in some information from a serial port, but when I
I'm trying to catch debug information from VMware. This might be an easy task
I'm currently trying to separate some of my code from my main form, and
I'm a newbie in WordPress. I'm trying to read information from a custom table
I'm trying to figure out a way to read GET method information from a
Trying to read an RSS and select information using Linq but can't seem 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.