Security Exception with new ExcelPackage(

Topics: Developer Forum
Mar 23, 2011 at 6:28 PM

I am getting a security exception when ExcelPackage() is hit. I have played around with as many security settings as I can think of (.net trust levels etc), but am having no luck. My code looks like:

FileInfo existingFile = new FileInfo(txtLocation.Text);
            using (ExcelPackage package = new ExcelPackage(existingFile))

{

}

 

The error I receive is:

 

Security Exception

Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. 

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

[SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
   System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
   System.Security.CodeAccessPermission.Demand() +54
   System.IO.FileInfo.get_DirectoryName() +137
   OfficeOpenXml.ExcelPackage.set_File(FileInfo value) +37
   OfficeOpenXml.ExcelPackage..ctor(FileInfo newFile) +39
   Cambria.Plugins.Admin.ImportColors.BtnImport_Click(Object sender, EventArgs e) in C:\EPiServer\Sites\Commerce\Plugins\Admin\ImportColors.aspx.cs:35
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +11041511
   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +11041050
   System.Web.UI.Page.ProcessRequest() +91
   System.Web.UI.Page.ProcessRequest(HttpContext context) +240
   ASP.plugins_admin_importcolors_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\root\e6b6f303\5913be2\App_Web_rig8afwm.1.cs:0
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +599
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +171

Any ideas would be great! Thanks in advance!