简体   繁体   中英

C# SecurityException when reading text file

I'm writing ac# 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; }
        }

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM