0

我正在编写 ac# 程序(具体来说是一个 IRC 机器人)并使用脚本库 Jint(http://jint.codeplex.com/)。我有一个链接到它的外部命令,当被调用时,它会从不同的文件中读取 .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; }
        }
4

1 回答 1

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。

于 2011-12-10T21:17:59.623 回答