none
Error CS0103 The name 'File' does not exist in the current context

    Question

  • Hi,

    I'm hoping this is going to be an easy one for someone. I'm getting the following error when compiling a simple program in Visual Studio 2015 (Community Edition)

    Error CS0103 The name 'File' does not exist in the current context.

    Now, I can get this same code to compile successfully in Visual Studio 2013 (Express) Desktop

    The line I suspect the compiler is choking on is this one:

    StreamReader reader = new StreamReader(File.OpenRead(@"C:\Users\xxxxxxx\Desktop\test.csv"));

    So the question being; why do I get this error in Visual Studio 2015 (Community Edition) and not in Visual Studio 2013 (Express) Desktop. The code is exactly the same and has the following at the top:

    using System.IO;

    Is there a setting in Visual Studio 2015 (Community Edition) that would need changing ?

    Any help with this would be greatly appreciated.

    Thanks in adv.

    Saturday, August 22, 2015 9:32 AM

Answers

  • Thanks for your reply. I tried doing that before I posted to this forum, but the error remains in Visual Studio 2015 (Community Edition).

    I've managed to work this out.

    I edited the project.json file and removed the following from the frameworks:

    "dnxcore50": {
                "dependencies": {
                    "System.Collections": "4.0.10-beta-23019",
                    "System.Console": "4.0.0-beta-23019",
                    "System.Linq": "4.0.0-beta-23019",
                    "System.Threading": "4.0.10-beta-23019",
                    "Microsoft.CSharp": "4.0.0-beta-23019"
                }
            }

    and just left the following:

    "dnx451": { }

    Now the project compiles with no errors.

    Thanks for you time.


    • Edited by levens2m Saturday, August 22, 2015 10:55 AM
    • Marked as answer by levens2m Saturday, August 22, 2015 10:56 AM
    Saturday, August 22, 2015 10:47 AM

All replies

  • If you added the namespace for System.IO, it should not give this error.

    Can you please using with using File from direct namespace?

    StreamReader reader = new StreamReader(System.IO.File.OpenRead(@"C:\Users\xxxxxxx\Desktop\test.csv"));

    Saturday, August 22, 2015 9:49 AM
  • I'm getting the following error when compiling a simple program in Visual Studio 2015 (Community Edition)

    Error CS0103 The name 'File' does not exist in the current context.

    The line I suspect the compiler is choking on is this one:

    StreamReader reader = new StreamReader(File.OpenRead(@"C:\Users\xxxxxxx\Desktop\test.csv"));


    "Suspect"? The compiler should tell you the line number where the error occurred, and
    usually if you double-click on the error message in the Errors window you will be taken
    directly to the error line in the source code window. (Based on experience with versions
    prior to Visual Studio 2015 (Community Edition)).

    - Wayne

    Saturday, August 22, 2015 10:07 AM
  • Thanks for your reply. I tried doing that before I posted to this forum, but the error remains in Visual Studio 2015 (Community Edition).

    I've managed to work this out.

    I edited the project.json file and removed the following from the frameworks:

    "dnxcore50": {
                "dependencies": {
                    "System.Collections": "4.0.10-beta-23019",
                    "System.Console": "4.0.0-beta-23019",
                    "System.Linq": "4.0.0-beta-23019",
                    "System.Threading": "4.0.10-beta-23019",
                    "Microsoft.CSharp": "4.0.0-beta-23019"
                }
            }

    and just left the following:

    "dnx451": { }

    Now the project compiles with no errors.

    Thanks for you time.


    • Edited by levens2m Saturday, August 22, 2015 10:55 AM
    • Marked as answer by levens2m Saturday, August 22, 2015 10:56 AM
    Saturday, August 22, 2015 10:47 AM
  • I had the same problems and this absolutely worked: 

    Thanks for your reply. I tried doing that before I posted to this forum, but the error remains in Visual Studio 2015 (Community Edition).

    I've managed to work this out.

    I edited the project.json file and removed the following from the frameworks:

    "dnxcore50": {
                "dependencies": {
                    "System.Collections": "4.0.10-beta-23019",
                    "System.Console": "4.0.0-beta-23019",
                    "System.Linq": "4.0.0-beta-23019",
                    "System.Threading": "4.0.10-beta-23019",
                    "Microsoft.CSharp": "4.0.0-beta-23019"
                }
            }

    and just left the following:

    "dnx451": { }

    Now the project compiles with no errors.

    Thanks for you time.



    Friday, December 04, 2015 12:25 AM