Reputation: 357
I'm trying to use EPPlus in Asp.net application And I'm getting this exception:
Attempt by security transparent method 'OfficeOpenXml.ExcelPackage.Init()' to access security critical method 'System.Text.CodePagesEncodingProvider.get_Instance()' failed.
System.MethodAccessException: Attempt by security transparent method 'OfficeOpenXml.ExcelPackage.Init()' to access security critical method 'System.Text.CodePagesEncodingProvider.get_Instance()' failed. Assembly 'EPPlus, Version=5.7.5.0, Culture=neutral, PublicKeyToken=ea159fdaa78159a1' is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model.
Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception. at
OfficeOpenXml.ExcelPackage.Init() at OfficeOpenXml.ExcelPackage..ctor() at
Utilities.Database.EPPlus.EPPlusHelpers.WriteToExcel(DataColumn[] columns, IEnumerable`1 data, Stream output, String worksheetName, ColumnFormatProvider formatProvider) at
WebClient.Reports.ReportsPane2.<>c__DisplayClass60_0.b__0(String tempFilename) at
Utilities.WebUI.Utils.ReturnGeneratedFile(Boolean returnInResponse, String tempPath, String
filename, String contentType, Encoding encoding, Action`1 fileGenerator) at
WebClient.Reports.ReportsPane2.ReportToExcel(Int32 controllerID, IEnumerable`1 dataPoints, Dictionary`2 displayInfo, Boolean displayDiscreteValues) at
WebClient.Reports.ReportsPane2.ReportDirectExport(ReportDefinition reportDef, ExportFormat exportFormat)
The Asp.net application is a .NET Framework 4.7.2 which references a .NET Standard 2.0 library protect which uses EPPlus 5.7.5 NuGet package.
I've tried adding
configuration>
<system.web>
<trust level="Full" />
</system.web>
</configuration>
to the web.config
, but it did not work.
The previous version of the application used .NET Framework 4.6 with a .NET Framework library project which referenced EPPlus 4.5.1 NuGet package, that worked ok.
Upvotes: 0
Views: 283
Reputation: 357
Managed to fix this problem by Changing the project that was using EPPlus to use multi targeting netstandard2.0 & net472. (luckily this project was used directly from the ASP.NET application)
Upvotes: 0