I am trying to read from an excel file in C# using NPOI. Below is the code snippet I am using to initialize my variables. But while initializing the workbook, below is the exception I am getting.
public class Excelhandler
{
public static XSSFWorkbook workbook;
public static FileStream fileStream;
static Excelhandler()
{
try
{
string pth = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
string actualPath = pth.Substring(0, pth.LastIndexOf("bin"));
string projectPath = new Uri(actualPath).LocalPath;
string path = projectPath + @"TestData\Data.xlsx";
//string path = ConfigurationManager.AppSettings["TestDataPath"];
fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
workbook = new XSSFWorkbook(fileStream);
}
The same piece of code was working in some other C# project but suddenly it's not working. Below are the versions I am using : -
NPOI-2.3.0
SharpZipLib(NPOI Dependency) - 1.0.0
.Net Framework -4.5.2
Exception - Attempt by security transparent method 'NPOI.OpenXml4Net.OPC.ZipPackage..ctor(System.IO.Stream, NPOI.OpenXml4Net.OPC.PackageAccess)' to access security critical method 'ICSharpCode.SharpZipLib.Zip.ZipInputStream..ctor(System.IO.Stream)' failed.