Trying to create a simple C# console application that interacts with both the EPPlus excel read/write library along with another third-party vendor application my company uses.
The challenge I'm facing is that the other third-party application requires my App.config file to enable support for the legacy CAS policy model, and is a prerequisite to access one of it's critical assemblies. Thus my settings look like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<runtime>
<NetFx40_LegacySecurityPolicy enabled="true"/>
</runtime>
</configuration>
When the legacy security policy is set to false, my code that interacts with the EPPlus assembly works flawlessly. When I change the legacy support policy to true, I immediate get an exception thrown for the following:
Unhandled Exception: 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 System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark)
at System.Security.CodeAccessPermission.Demand()
at System.Security.Permissions.FileIOPermission.QuickDemand(FileIOPermissionAccess access, String fullPath, Boolean checkForDuplicates, Boolean needFullPath)
at System.IO.FileSystemInfo.get_FullName()
at OfficeOpenXml.ExcelPackage.ConstructNewFile(String password)
at OfficeOpenXml.ExcelPackage..ctor(FileInfo newFile)
at EPPlusApp.Program.Main(String[] args)
Tried manually setting FileIOPermission for the directory & excel files I planned to read/write, and spent half the day scouring through forums to identify a solution, but to no avail.
Anyone aware of a potential work-around to get the EPPlus assembly functional while keeping the legacy security policy enabled?