读取文本文件时 C# SecurityException
我正在编写 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; }
}
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; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Lorem ipsum dolor sat amet,consectetur adipiscing elit。 Aliquam nunc nisi、aliquam et rhoncus id、egestas 坐 amet turpis。 Nunc placerat Massa ultricies posuere luctus。
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.