none
Interesting Security Exception for one user RRS feed

  • Question

  • Hello,

    I am developing a C# application that pulls data from SQL-Server and, via Microsoft.Office.Interop.Excel, generates an Excel spreadsheet.  This application works on my PC, as well as those of a few other developers in my group.

    However, the PC of the QA guy is somehow different.  It throws a security exception when my application attempts to display a file dialog box.  The QA guy is a local admin on his box, so I'm not sure why there would be a problem with Security.  The System Administrators advised me that this is not controlled by group policy.

    Here is an excerpt of the exception:

    System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
       at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
       at System.Security.CodeAccessPermission.Demand()
       at System.Windows.Forms.FileDialog.set_FileName(String value)
       at AgentSplitsReportII.agentSplitsForm.runRptBtn_Click(Object sender, EventArgs e)
    Here's the code in question.  I believe the exception is occuring on the line "asrSaveFileDialog.FileName = 'AgentSplitsReport.xls';"
    private void runRptBtn_Click(object sender, EventArgs e)
            {
                string myFilePath;
                DialogResult myDialogResult;
    
                asrSaveFileDialog.Filter = "Excel Spreadsheets|.xls";
                asrSaveFileDialog.FileName = "AgentSplitsReport.xls";
                myDialogResult = asrSaveFileDialog.ShowDialog();
    
                if (myDialogResult == DialogResult.OK)
                {
                    myFilePath = asrSaveFileDialog.FileName;
                    ExcelFileCreator.CreateExcelFile(myFilePath);
    
                }
            }
    Any ideas where I should go with this?

    Thanks,
    -Josh
    Monday, January 18, 2010 5:26 PM

All replies

  • Hi Josh,

    Based on the error information, it is one CAS(code access security) issue. For more information about CAS, please refer to this link:
    http://msdn.microsoft.com/en-us/library/930b76w0.aspx

    Code access security is a mechanism that helps limit the access that code has to protected resources and operations. In the .NET Framework, code access security performs the following functions:

    • Defines permissions and permission sets that represent the right to access various system resources.

    • Enables administrators to configure security policy by associating sets of permissions with groups of code (code groups).

    • Enables code to request the permissions it requires in order to run, as well as the permissions that would be useful to have, and specifies which permissions the code must never have.

    • Grants permissions to each assembly that is loaded, based on the permissions requested by the code and on the operations permitted by security policy.

    • Enables code to demand that its callers have specific permissions.

    • Enables code to demand that its callers possess a digital signature, thus allowing only callers from a particular organization or site to call the protected code.

    • Enforces restrictions on code at run time by comparing the granted permissions of every caller on the call stack to the permissions that callers must have.

    In the offending computer CLR doesn't grant the FileIOPermission to your application. You can use this tool:
    .NET Framework Configuration Tool (Mscorcfg.msc) to evaluate an assembly for its permission so as to fix this issue.
    http://msdn.microsoft.com/en-us/library/2bc0cxhc.aspx


    Best regards,
    Riquel
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, January 20, 2010 6:01 AM
    Moderator