스크립트 라이브러리 Jint (http://jint.codeplex.com/)를 사용하여 C# 프로그램 (특정 IRC 봇)을 작성하고 있습니다. 다른 파일에서 .js 텍스트 스트림을 읽을 때 연결된 외부 명령이 있습니다. 첫 번째 파일을 읽는 것은 잘 작동하지만 내가 다른 하나를 읽을 때 내가 얻을 메시지는 다음과 같습니다텍스트 파일을 읽을 때 C# SecurityException이 발생했습니다.
이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; }
}
응용 프로그램이 실행되는 계정에 파일을 읽을 수있는 적절한 권한이 있습니까? 또한, 당신은 그것을 그냥 다시 던지기 위해 예외를 잡아서는 안됩니다. try/catch 블록을 완전히 그대로 두거나 catch (Exception e) {throw; }'스택 추적을 유지 관리합니다. –
예, 읽은 첫 번째 파일은 같은 폴더에 있으며 관리자 계정으로 실행됩니다. –
응용 프로그램이 부분 신뢰 (partial-trust, CAS)로 실행되고 있습니까? – Josh