Error creating password protected workbook

Dec 8, 2014 at 12:12 PM
Edited Dec 8, 2014 at 12:13 PM
I am simply trying to save a ExcelPackage with password like p.Save("123456") when this exceptions is raised:
A first chance exception of type 'System.MethodAccessException' occurred in EPPlus.dll

Additional information: Attempt by security transparent method 'OfficeOpenXml.Utils.EncryptedPackageHandler.EncryptPackage(Byte[], OfficeOpenXml.ExcelEncryption)' to call native code through method 'OfficeOpenXml.Utils.EncryptedPackageHandler.CreateILockBytesOnHGlobal(IntPtr, Boolean, OfficeOpenXml.Utils.ILockBytes ByRef)' failed.  Methods must be security critical or security safe-critical to call native code.
It is raised on this row in EncryptedPackageHandler.cs:
        var iret = CreateILockBytesOnHGlobal(IntPtr.Zero, true, out lb);
Any ideas?

Running x64 version of Windows 8.