读取文本文件时出现C#SecurityException

时间:2011-12-10 19:58:52

标签: c# javascript text streamreader jint

我正在编写一个c#程序(一个特定的IRC bot)并使用脚本库Jint(http://jint.codeplex.com/)。我有一个外部comamnd链接到它,当被调用时从另一个文件中读取.js文本流。读取第一个文件工作正常,但是当我读到另一个文件时,我得到的信息是:

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.

抛出异常的c#函数是:

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; }
        }

1 个答案:

答案 0 :(得分:2)

Lorem ipsum dolor坐下来,精神上的精神。 Aliquam nunc nisi,aliquam et rhoncus id,egestas sit amet turpis。 Nunc placerat massa ultricies posuere luctus。