私はC#プログラム(具体的にはIRCボット)を作成し、スクリプトライブラリJint(http://jint.codeplex.com/)を使用しています。他のファイルから.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; } 'は、スタックトレースを維持します。 –
はい、読み込んだ最初のファイルは同じフォルダにあり、管理者アカウントで実行されます。 –
アプリケーションがパーシャルトラスト(CAS)で実行されていますか? – Josh