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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:55:30+00:00 2026-05-29T22:55:30+00:00

Documentation says: // Summary: // Creates a new file, writes the specified string to

  • 0

Documentation says:

// Summary:
//     Creates a new file, writes the specified string to the file, and then closes
//     the file. If the target file already exists, it is overwritten.

First line, first sentence: Creates a new file, and on the exceptions it lists:

//   System.IO.FileNotFoundException:
//     The file specified in path was not found.

In which case would this happen? If it always create a file then it shouldn’t thrown a FileNotFoundException…

Is the documentation wrong? Or is it missing a <remarks> tag perhaps?

  • 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-29T22:55:31+00:00Added an answer on May 29, 2026 at 10:55 pm

    File.WriteAllText eventually calls:

    private static void InternalWriteAllText(string path, string contents, Encoding encoding)
    {
        using (StreamWriter streamWriter = new StreamWriter(path, false, encoding))
        {
            streamWriter.Write(contents);
        }
    }
    

    All of the exceptions thrown prior to the call to InternalWriteAllText throw ArgumentException or ArgumentNullException but theoretically (since FileStream can throw the exception) the streamWriter.Write(contents); could potentially throw the exception. Very unlikely though based on what it does and how the streamWriter is opened.

    I wouldn’t necessarily say the doc is wrong per se, more that MS is covering their butt by documenting the (very rare) possibility.

    Source: Decompiling mscorlib v4.0.0.0 using ILSpy.

    UPDATE

    Just checked mscorlib v2.0.0.0, same case except it contains fewer sanity checks (meaning it basically translates directly to the code above).

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

Sidebar

Related Questions

Python documentation says that os.rename(src, dst) ... On Windows, if dst already exists, OSError
The documentation says about timerWithTimeInterval:target:selector:userInfo:repeats: Returns a new NSTimer that, when added to a
The documentation says that if I already have virtualenv installed, then pip is available
XML::Simple documentation says to initiate the data structure with an XML file, using XMLin('[FILENAME]')
Rack documentation says that File servers support X-Cascade header rack-mount says that Rack::Mount supports
OK, the documentation says: If you configure the folder containing FW/1 as a new
wcstombs documentation says, it converts the sequence of wide-character codes to multibyte string. But
My documentation says Click on the target and add pgmName.a on General settings of
The Java language documentation says: If a primitive type or a string is defined
Documentation says: The Grails team discourages the embedding of core application logic inside controllers,

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.