If File Exists Method (C#)

Programming, for all ages and all languages.
Post Reply
ieatlotz
Posts: 1
Joined: Tue Mar 15, 2011 9:07 pm

If File Exists Method (C#)

Post by ieatlotz »

I'm working on a dos style operating system. For this I'm using Cosmos.

I have a problem on my file manager, when I use the code:

Code: Select all

           using System;
           using System.IO;

            // See if this file exists from user input (whats typed)
            if (File.Exists(UserInput))
            {
                Console.WriteLine("The file exists.");
            }
I get the error:

Code: Select all

*** System Fault *** General Protection Fault at 0x005ADF6F
Does anyone know a solution to this problem?
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

Re: If File Exists Method (C#)

Post by Tosi »

Maybe.

I have never programmed a line of C# before so expect this to be wrong.
Are you sure the File.Exists method is implemented, either by Cosmos or yourself? Is the implementation complete? Is there any line of code within that method that seems to be causing the fault?

Can you get more information about the General Protection Fault? What caused it, what were the values of the registers, a stack dump?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: If File Exists Method (C#)

Post by Solar »

Double-check that UserInput is of type System::String. Print it before calling File.Exists().

(I know that a mismatch should result in a compile-time error, but I don't know how faithfully the Cosmos environment and compiler handle this. I always recommend to assert the basic assumptions first.)
Every good solution is obvious once you've found it.
Post Reply