gpt4 book ai didi

读取文本文件时 C# SecurityException

转载 作者:行者123 更新时间:2023-12-02 19:57:16 29 4
gpt4 key购买 nike

我正在编写一个 C# 程序(具体来说是一个 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; }
}

最佳答案

Lorem ipsum dolor sat amet,consectetur adipiscing elit。 Aliquam nunc nisi、aliquam et rhoncus id、egestas 坐 amet turpis。 Nunc placerat Massa ultricies posuere luctus。

关于读取文本文件时 C# SecurityException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8459433/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com