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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:41:56+00:00 2026-06-18T22:41:56+00:00

This method: private async Task readFileInfo(string folderId) Has a call to another method: importCount

  • 0

This method:

private async Task readFileInfo(string folderId)

Has a call to another method:

importCount = await VM.importVehicles(myXDoc);

Defined here: (note: I changed it from a for loop to a for each but I’m getting similar results).

public async Task<Int32> importVehicles(XDocument importXMLDocument)
{
    var Importedvehicles = from vehicle in importXMLDocument.Descendants("vehicle")
                           select new
                           {
                               VehicleName = vehicle.Element("VehicleName").Value,
                               VehicleYear = vehicle.Element("VehicleYear").Value,
                               Odometer = vehicle.Element("Odometer").Value,
                               LicensePlate = vehicle.Element("LicensePlate").Value,
                               OilWeight = vehicle.Element("OilWeight").Value,
                               OilQuantity = vehicle.Element("OilQuantity").Value,
                               OilFilterModelNumber = vehicle.Element("OilFilterModelNumber"),
                               AirFilterModelNumber = vehicle.Element("AirFilterModelNumber"),
                               OilChangedDate = vehicle.Element("OilChangedDate"),
                               OilChangedOdometer = vehicle.Element("OilChangedOdometer"),
                               NextOilChangeDate = vehicle.Element("NextOilChangeDate"),
                               NextOilChangeOdometer = vehicle.Element("NextOilChangeOdometer"),
                               SettingDistance = vehicle.Element("SettingDistance"),
                               SettingMonths = vehicle.Element("SettingMonths"),
                           };

    Int32 vehicleId;
    vehicleId = await getMaxVehicleId();
    try
    {

        foreach (var item in Importedvehicles)
        {
            vehicle myImportedVehicle = new vehicle();
            myImportedVehicle.VehicleId = vehicleId += 1;
            myImportedVehicle.ImagePath = "Assets/car2.png";
            myImportedVehicle.VehicleName = item.VehicleName;
            myImportedVehicle.VehicleModel = item.VehicleName;


            myImportedVehicle.VehicleYear = short.Parse(item.VehicleYear);
            myImportedVehicle.CurrentOdometer = Convert.ToInt32(item.Odometer);
            myImportedVehicle.LicensePlate = item.LicensePlate;
            myImportedVehicle.LastOilChangedDate = Convert.ToDateTime(item.OilChangedDate.Value.ToString()).ToString("d");
            myImportedVehicle.LastOilChangedOdometer = (Int32)item.OilChangedOdometer;
            myImportedVehicle.ReminderDistance = (Int32)item.SettingDistance;
            myImportedVehicle.ReminderMonths = (Int32)item.SettingMonths;

            vehicleInformation myImportVI = new vehicleInformation();
            myImportVI.OilWeight = item.OilWeight;
            myImportVI.OilAmount = item.OilQuantity;
            myImportVI.OilFilterNumber = item.OilFilterModelNumber.Value.ToString();
            myImportVI.AirFilterNumber = item.AirFilterModelNumber.Value.ToString();

            myImportedVehicle.vehicleInfo = myImportVI;
            m_vehicles.Add(myImportedVehicle);
        }
    }
    catch (Exception ex)
    {
        System.Diagnostics.Debug.WriteLine(ex.Message.ToString());
    }

        await SaveList();
        return Importedvehicles.Count();
    }

I’m getting an error:

Object reference not set to an instance of an object.

when I step through it the iVehicle is highlighted but then it goes directly to the for statement. Then it errors as it looks as it hasn’t gotten the results from iVehicle yet.

  • 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-18T22:41:57+00:00Added an answer on June 18, 2026 at 10:41 pm

    This doesn’t 100% answer your question, but it should give you a good start.

    The reason the debugger jumps straight into the for...loop after the declaration of iVehicle, is because your query does not get executed when you declare it. Therefore, iVehicle at that point is not a collection of anonymous types.

    When you call .Count(), the query is being executed and iVehicle is attempting to be turned into a proper collection of anonymous types. However, because something in the query (that is being executed after you call .Count()) is null, you’re receiving an NullReferenceException.

    You should start by verifying that both importXMLDocument and the return value from the call to Descendants() is not null.

    Hope that helps anyway.

    EDIT:

    Now that you’ve given a complete example, you have heaps of places that could potentially be null.

    Each time you use this:

    vehicle.Element("SomeElementNameHere")
    

    That could potentially be null. Then you’re calling the .Value property on a null object.

    You need to make sure each element is definitely there. Isolate each case, and determine which one is null.

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

Sidebar

Related Questions

I have a method like this: private async Task DoSomething() { // long running
click the button to call this method: private void goRegister(final boolean isUsername) { new
I have a method private static DataTable ParseTable(HtmlNode table) and sometimes this method has
I have this method to transfer files using a FTP Server: private void TransferNeededFiles(IEnumerable<string>
When i run this demo it's call TestBean's writeObject method which is private How
I have a method like this, that hangs when declaring responseObject using Task.Factory.FromAsync() private
I have a method that looks like this: private async void DoStuff(long idToLookUp) {
Consider this, Task task = new Task (async () =>{ await TaskEx.Delay(1000); }); task.Start();
I have a problem with async-await expression which returns wrong result. private Task<int> A
I have the following method which uses implicit scheduling: private async Task FooAsync() {

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.