none
Upgrading to 4.6.2 fails File.Exists check RRS feed

  • Question

  • I upgraded my .NET project from 4.5.1 to 4.6.2. Whenever I am doing a System.IO.File.Exists check, it always returns false even though the file does exist. When I change my httpruntime in the web.config to any version lower than 4.6.2, the File.Exists works fine. Has anybody come across this scenario. Why does changing .net version to 4.6.2 , stop identifying if a file exists or not. 

    Wednesday, April 18, 2018 4:57 PM

All replies

  • Note that File.Exists also checks for permissions. Maybe these aspects were improved. Have you tried to read the file even if File.Exists returns false?

    Wednesday, April 18, 2018 6:15 PM
  • No, have not tried that. Will try and see what happens. Thanks!
    Wednesday, April 18, 2018 7:31 PM
  • Hi MSUserDotNet,

    Thank you for posting here.

    For your question, I check the source code of .net framework 4.5.1 and .net framework 4.6.2. It's the same. Normally, the version of the .net framework should not affect the return value of File.Exists.

    Like Viorel_ said, if the caller does not have sufficient permissions to read the specified file, no exception is thrown and the method returns false regardless of the existence of path.

    Have you do some another operations for this file? Be aware that another process can potentially do something with the file in between the time you call the Exists method and perform another operation on the file, such as Delete.

    The Exists method returns false if any error occurs while trying to determine if the specified file exists. This can occur in situations that raise exceptions such as passing a file name with invalid characters or too many characters, a failing or missing disk, or if the caller does not have permission to read the file.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by zarahhhh Thursday, April 26, 2018 2:15 AM
    Monday, April 23, 2018 7:08 AM
    Moderator