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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:28:16+00:00 2026-06-14T20:28:16+00:00

My application is already working it can detect the xml file and prompt the

  • 0

My application is already working it can detect the xml file and prompt the content of the xml file but sometimes it will prompt “Root element is missing”, and sometimes also it is okay but when I open the xml file, it is ok, it has contents on it. How to solve this issue.

Here is the screenshot of the error:

enter image description here

Here is the code:

private void fileSystemWatcher_Created(object sender, System.IO.FileSystemEventArgs e)
    {
        string invoice = "";
        using (var stream = System.IO.File.Open(e.FullPath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite))
        {
            var doc = System.Xml.Linq.XDocument.Load(stream);
            var transac = from r in doc.Descendants("Transaction")
                          select new
                          {
                              InvoiceNumber = r.Element("InvoiceNumber").Value,
                          };

            foreach (var i in transac)
            {
                invoice = i.InvoiceNumber;
            }
        }

        MessageBox.Show(invoice);
        fileSystemWatcher.EnableRaisingEvents = false;
    }

The error goes here var doc = System.Xml.Linq.XDocument.Load(stream);

  • 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-14T20:28:17+00:00Added an answer on June 14, 2026 at 8:28 pm

    The FileSystemWatcher will raise the event very quickly when the file chanes. It is possible that the write operatrion has not finished before you read the file.

    To test that, add a Thread.Sleep(100); before you read the file as a quick workaround.

    To get a better solution, do not open the file in shared mode, but try if you can open it exclusively. If this fails, wait some milliseconds and try again – until you can open the file exclusively. Also take care that the event might be triggered more than once – this depends on how the other task writes to the file.

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

Sidebar

Related Questions

I am already working on a .net project but I think this question can
I'm working on an iOS application where most of the backend has already been
Suppose this simple scenario: My client has an already working .net application and he/she
My use-case: I already have a working ASP.NET application I would like to implement
I'm thinking of integrating a chat inside an already written and working php application.
I have a C# application using pop this is already working perfectly fine. However,
I have an application I have already started working with and it seems I
I have a working web application which already has a login and registration system.
I'm working on a small but vital batch application which has a step in
I already started working on a few small Cocoa Application. It works just fine,

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.