2011-12-10 21 views
0

私は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; } 
     } 
+2

アプリケーションが実行されているアカウントには、ファイルを読み取るための適切な権限がありますか?また、そのように再スローするだけで例外をキャッチしてはいけません。 try/catchブロックを完全に抜けるか、catch(Exception e){throw; } 'は、スタックトレースを維持します。 –

+0

はい、読み込んだ最初のファイルは同じフォルダにあり、管理者アカウントで実行されます。 –

+1

アプリケーションがパーシャルトラスト(CAS)で実行されていますか? – Josh

答えて

2

Loremのイプサムの悲しみは、AMET consecteturのadipiscingに座りますエリート。 Aliquam nunc nisi、aliquam et rhoncus id、egestas amet turpis。ルンクトゥスの象徴的な儀式は、

+0

魅力的に働いた、ありがとう。 –

関連する問題