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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:49:05+00:00 2026-06-13T11:49:05+00:00

ASPX.NET application that uses XDocument.Load() to read from an XML file. At times it

  • 0

ASPX.NET application that uses XDocument.Load() to read from an XML file. At times it will throw an IOException static that the file cannot be opened b/c it is in use by another process. I cannot recreate this at will by opening the file and reloading the site. But what’s even more odd is that the exception occurs from within a Try-Catch block where I am explicitly catching System.IOException.

Here is the stack:

Exception type: IOException

Thread information:
Thread ID: 18
Thread account name: NT AUTHORITY\NETWORK SERVICE
Is impersonating: False
Stack trace: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
at System.Xml.XmlReaderSettings.CreateReader(String inputUri, XmlParserContext inputContext)
at System.Xml.XmlReader.Create(String inputUri, XmlReaderSettings settings, XmlParserContext inputContext)
at System.Xml.Linq.XDocument.Load(String uri, LoadOptions options)
at System.Xml.Linq.XDocument.Load(String uri)

at StatTick.Controls.ChartSlider.getXMLFile(String url) in removedpath\StatTick\Controls\ChartSlider.ascx.cs:line 27
at StatTick.Controls.ChartSlider.Page_Load(Object sender, EventArgs e) in removedpath\StatTick\Controls\ChartSlider.ascx.cs:line 21

Here is the code:

private XDocument getXMLFile(string url)
    {
        XDocument tempDoc;

        t("Looking For XML File");
        int tryCount = 0;
        //string URL = "~/tempCharts/imageList.xml";
        while (tryCount++ < 10)
        {

            try
            {
                tempDoc = XDocument.Load(Server.MapPath(url));
                return tempDoc;
            }
            catch (IOException)
            {
                t("Error accessing XML File, sleeping for 10ms and then trying again\r\nTryCount: " + tryCount.ToString());
                Thread.Sleep(10);
                continue;

            }
        }

        return null;
    }

Hopefully someone will be able to offer some insight into this matter for me.

Thanks

EDIT
Ok here is what I’ve Done, I’ll have to do some testing to verify it no longer throws Thanks for the quick responses!:

while (tryCount <= 10)
        {
            try
            {
                using (FileStream fStream = new FileStream(Server.MapPath(url), FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    XDocument xDoc = XDocument.Load(fStream);

                    foreach (XElement xe in xDoc.Descendants("ImageUrl"))
                    {
                        t("Added: " + xe.Value);
                        tempImageUrlList.Add(xe.Value);
                    }
                    t("Done with Image List!");
                }
                return tempImageUrlList;
            }
            catch (Exception)
            {
                t("Error access XML File, sleeping for 10ms and then trying again\r\nTryCount: " + tryCount.ToString());
                Thread.Sleep(10);
                continue;
            }
        }
  • 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-13T11:49:06+00:00Added an answer on June 13, 2026 at 11:49 am

    use a stream instead and use it load the XML.You can be sure that the underlying stream is closed with a using statement.

    using (Stream s = File.OpenRead(Server.MapPath(url)))
    {
            XDocument.Load(s);
    }
    

    Or

    using (FileStream fs= new FileStream(Server.MapPath(url), FileMode.Open,
                                              FileAccess.Read, FileShare.Read))
    {
            XDocument.Load(fs);
    }
    

    ;

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

Sidebar

Related Questions

I'm am creating an ASP.NET 2.0 web application that uses a BasePage.aspx that is
I am working on an application in ASP.NET Development Server 10.0.0.0 that uses external
I'm building an asp.net page that uses a page method call from jquery. This
We have an ASP.NET web application which uses ASP.NET Ajax. We open it from
We have an ASP.NET web application running in IIS that uses the SoapHttpClientProtocol class
I have an ASP.NET (C#) application, written with VS 2008, that uses CodeBehind files
I've a little problem, with a ASPX .NET application that I'm updating. After having
I have an ASP.Net webforms application that uses the .Net globalization features to deliver
Background: I have a winform application written in VB.NET that uses a WebService to
I have an ASP.NET application that uses the Fluorine FX remoting library. When the

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.