System.Security.Permissions.FileIOPermission - Failed

Oct 1, 2010 at 10:15 PM

Ok, all I did was copy the DLL into my ASP.net 3.5, c# project and ran the following code.

                using (ExcelPackage package = new ExcelPackage(existingFile))
                {
                    ReturnTable = new DataTable("ExcelTabs");
                    ReturnTable.Columns.Add("WorksheetName", System.Type.GetType("System.String"));

                    foreach (ExcelWorksheet Worksheet in package.Workbook.Worksheets)
                    {
                        DataRow row = ReturnTable.NewRow();
                        row[0] = Worksheet.Name;
                    }
                }

It gives me the following error:

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

On the line "using (ExcelPackage package = new ExcelPackage(existingFile))".

The "existingFile" is pointing to a tempFiles folder under the website main folder.  I have given full rights to the "network service" and "ASP.Net" accounts for the whole website, including that folder.  Any ideas?

 

 

 

Coordinator
Oct 3, 2010 at 6:00 PM

That should work fine if you have the correct permissions. Make sure the user running under the application pool has the right permissions.

Oct 4, 2010 at 12:47 PM

The project that is running is the local one that is created when you start an application in Visual Studio.  I don't know of a place to control the application pool from.

Coordinator
Oct 4, 2010 at 1:50 PM

ok, you use the internal webserver in vs2010? Can you run the code from a console/win app?

Are you local admin on your machine. If not, do you get it to work if you start VS as Local admin?

Also, check the event log for any messages.

Can you read the file using a normal FileStream?

 

Oct 4, 2010 at 2:15 PM

Ok, I found some more information.  The line before the using listed above is this:

FileInfo existingFile = new FileInfo(LocalFileName);

I use reflector and can see that once processing enters the DLL, that it can no longer see the FileInfo.  I also extracted this error out

 

The assembly or AppDomain that failed was:
EPPlus, Version=2.7.0.1, Culture=neutral, PublicKeyToken=ea159fdaa78159a1
The Zone of the assembly that failed was:
Internet
The Url of the assembly that failed was:
file:///C:/inetpub/DRBweb_3.5//DRBWEB_3.5/bin/EPPlus.DLL

Oct 4, 2010 at 2:17 PM

I am using VS2008.  This application is setup to use a website on the local IIS on my local box.  When I run your sample applicaiton I have no issues.

When I start up my application, I have to be in local admin mode on my system.

Will check the event log and try to read the file via a normal FileStream.

 

 

Oct 4, 2010 at 2:18 PM

Oh, my local box is Windows 7 with IIS 7

Coordinator
Oct 4, 2010 at 2:19 PM

Try to download the source and run it with your code.

Oct 4, 2010 at 2:23 PM

Sorry but I don't see where to download the source.

Coordinator
Oct 4, 2010 at 2:23 PM

From the source code tab

Oct 4, 2010 at 2:24 PM

Yep, just found it.  Thanks.  :)

Oct 4, 2010 at 2:32 PM

Nope didn't help. 

Oct 4, 2010 at 2:48 PM

In case it helps, here is more of the code.

        public DataTable GetExcelTabNames()
        {
            DataTable ReturnTable = null;

            try
            {
                if (File.Exists(LocalFileName) == false)
                    GetExcelFile();

                FileInfo existingFile = new FileInfo(LocalFileName);

                // the using statement automatically calls Dispose() which closes the package.
                using (ExcelPackage package = new ExcelPackage(existingFile))
                {
                    ReturnTable = new DataTable("ExcelTabs");
                    ReturnTable.Columns.Add("WorksheetName", System.Type.GetType("System.String"));

                    foreach (ExcelWorksheet Worksheet in package.Workbook.Worksheets)
                    {
                        DataRow row = ReturnTable.NewRow();
                        row[0] = Worksheet.Name;
                    }
                }
            }
            catch (Exception ex)
            {
                string Message = "Description:  Error Getting Excel Tab Names."
                    + ", Method: DRB.Web.Accounts.Upload.UploadUtilVersion2.ExcelTabNames()"
                    + ", Error Message:" + ex.Message
                    + ", Error Source:" + ex.Source;

                EventLog.WriteEntry("DRBweb 1.1", Message, EventLogEntryType.Error);
                throw (ex);
            }

            return ReturnTable;
        }

Oct 4, 2010 at 3:16 PM

OK, I don't know what caused it but it started working.  I believe it was a security issue.  After it started working, I started backing out changes.  They are all backed out and it is still working!  I don't know what to think, but I will count it as a blessing and move forward. 

 

I am now getting a corrupted data error.  I will research that now.

 

Thanks a ton for your help jankallman.

Dec 3, 2010 at 2:13 PM

i had same errors - System.Security.Permissions.FileIOPermission - on lines, where FileInfo methods were called

i edited ExcelPackage.cs, compiled and they're gone

 

Sep 6, 2013 at 5:02 PM
I have the same issue here. It works on my PC (Windows 7 64 bit), but it does not work on other 32 bit PC. It prompts the same error even if i re-compile the code in 32 bit environment. However, this error only happen when the DLL is called with Labview. It is working fine if it is called by the sample program.

Please help.

Br,
KT.