What is the difference between this code

using (var fileStream = new FileStream(settingsFilename,
                                       FileMode.Open))
{
    return ReadSettings(fileStream);
}
And this code
using (var fileStream = new FileStream(settingsFilename,
                                       FileMode.Open,
                                       FileAccess.Read))
{
    return ReadSettings(fileStream);
}

Almost nothing, just a little FileAccess.Read !

But this little thing makes a big difference when you run your software in a secured environment.

The application with this piece of code was deployed to a customer reporting that the application was crashing at a the point of reading the settings. Weird, really weird. After getting back the log and I finally discovered that using juste FileMode.Open needs modify rights and that’s was the issue because the customer deploy the settings file on a folder in which the user doesn’t have the modify rights.

Comment and share

  • page 1 of 1
Author's picture

Laurent Kempé

I am an experienced Team Leader & Distinguished Solution Architect with a passion for shipping high-quality products by empowering development team and culture toward an agile mindset. I bring technical vision and strategy, leading engineering teams to move product, processes and architecture forward.


Team Leader, Distinguished Solutions Architect


Illzach, France