0

I'm writing a c# program (An IRC bot to be specific) and using the scripting library Jint ( http://jint.codeplex.com/ ). I have an external comamnd linked into it that when called reads a .js text stream from a different file. Reading the first file works fine, but when I read the other one the message I get is:

System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' failed.
   at HgpBot.Program.TextFile(String path) in C:\Users\Jake\Documents\Visual Studio 2010\Projects\HgpBot\HgpBot\Program.cs:line 167
   at HgpBot.ExternalCommands.DoFile(Plugin p, IrcEventArgs e, String FilePath)
in C:\Users\Jake\Documents\Visual Studio 2010\Projects\HgpBot\HgpBot\ExternalCommands.cs:line 76
The action that failed was:
Demand
The type of the first permission that failed was:
System.Security.Permissions.FileIOPermission
Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

The c# function throwing the exception is:

public static List<String> TextFile(String path)
        {
            List<String> result = new List<string>();

            try
            {
                using (TextReader tr = new StreamReader(path))
                {
                    String line;

                    while ((line = tr.ReadLine()) != null)
                    {
                        result.Add(line);
                    }
                }    

                return result;
            }
            catch (Exception e) { throw e; }
        }
  • 2
    Does the account under which the application is running have appropriate permissions to read the file? Also, you shouldn't catch an exception just to rethrow it like that. Leave the try/catch block out entirely, or do `catch (Exception e) { throw; }`, which maintains the stack trace. – Daniel Mann Dec 10 '11 at 20:11
  • Yes, as the first file it read is in the same folder, and it's run under an administrator account. –  Dec 10 '11 at 20:14
  • 1
    Is your application is running with Partial-Trust (CAS)? – Josh Dec 10 '11 at 20:18
  • Can't say I know what that is. –  Dec 10 '11 at 20:21
  • Are you running the code off your local machine or a somewhere on the network/internet? – Josh Dec 10 '11 at 20:25
  • This is all on the local machine, the only thing that involves any external internet connection is the IRC connection, which isn't connected at this point. –  Dec 10 '11 at 20:30

1 Answers1

2

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam nunc nisi, aliquam et rhoncus id, egestas sit amet turpis. Nunc placerat massa ultricies posuere luctus.

RC4
  • 36
  • 3