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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:44:15+00:00 2026-05-30T01:44:15+00:00

I have an xml file which i use for database, meaning that the xml

  • 0

I have an xml file which i use for database, meaning that the xml is updated frequently.
For the xml database have a FileWatcher, and once the xml is updated i get an event and then i deserialize the xml into object and check if there were indeed changes.

The problem that i have is that once i deserialize the xml, the Stream Reader is locking the file so i might get exceptions when trying to update it.

Is there a possibility to deserialize the xml without locking the file?

        XmlSerializer serializer = new XmlSerializer(typeof (MyType));
        Stream reader = new FileStream(File, FileMode.Open);
        var myType = (MyType) serializer.Deserialize(reader);
  • 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-05-30T01:44:16+00:00Added an answer on May 30, 2026 at 1:44 am
    new FileStream(File, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
    

    FileShare.ReadWrite is the key. Please remember to put filestreams into a using-statement!

    Edit: According the the comments (thanks!) there is still a problem if the other process writing to the file demands FileShare.None. This might well be the case in case of a writer. If this is the case the only solution is to operate on distinct files. I’d propose that you rename the file from “file.dat” to “file_readonly1.dat” on the first access after the write. Your reading processes can then read the file as many times as they want without blocking off the writer. The writer will just create a new file the next time it runs. Once some reader sees the new “file.dat” it will rename it to “file_readonly2.dat”. From then on readers should use the newer version of the file. And so on. I think this scheme is 100% safe.

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

Sidebar

Related Questions

I have a XML file that i'm going to use as a database for
I have a class which expects a stream that contains an XML file. I
I receive a daily XML file which I use to update a database with
I have an XML file which I need to parse using PHP and send
I have an XML file which XML parser choke on. A part of it
I have an XML file which has many section like the one below: <Operations>
I have an XML file which I'd like to parse into a non-XML (text)
Good morning. I have an XML file which contains lists of warning and errors
Im using c# .net , windows form application. I have a XML file which
We have a PageRoles xml file which contains the page path and the user

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.