1

I am using Gembox to open, modify and save a xlsx file. Calling Save on the Excelfile causes a System.IO.FileNotFoundException.

The problem happens with our company serial key and with the free key.

Sample Code

using GemBox.Spreadsheet;
namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        { 
            var path = @"C:\code\GemboxTest\App.xlsx"; 
            SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
            ExcelFile ef = ExcelFile.Load(path); 
            ExcelWorksheet ws = ef.Worksheets[0]; 
            //ws.Columns[0].Cells[0].Value = 42; 
            ef.Save(path); // <--------------------------------- Crash!
        }
    }
}

Error message

Could not load file or assembly 'System.Security.Permissions, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
System.Security.Permissions, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51

Stacktrace

at   .(Stream , Byte[] , Int32 , Int32 , String )
at   .(Stream )
at   .(Stream )
at   . ()
at   .(Stream )
at    .Dispose()
at   .   ​ (Boolean )
at   .Dispose()
at    .    ​ ()
at    .(Boolean )
at    .Dispose()
at GemBox.Spreadsheet.XlsxSaveOptions.(ExcelFile , Stream ,     )
at GemBox.Spreadsheet.XlsxSaveOptions.Save(ExcelFile excelFile, Stream stream, String path)
at GemBox.Spreadsheet.SaveOptions.(ExcelFile , String )
at GemBox.Spreadsheet.ExcelFile.Save(String path, SaveOptions options)
at GemBox.Spreadsheet.ExcelFile.Save(String path)
at ConsoleApp.Program.Main(String[] args) in C:\code\GemboxTest\ConsoleApp\Program.cs:line 14

Versions

  1. .NET Core 3.1 (also fails with 3.0)
  2. GemBox.Spreadsheet Version=45.0.1131
  3. Visual Studio 2019 (VisualStudioVersion = 16.0.29905.134)
  4. Windows 10 pro 64bit

Sample csproj file

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="GemBox.Spreadsheet" Version="45.0.1131" />
</ItemGroup>
</Project>
Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
nomiso1183
  • 33
  • 5

2 Answers2

2

Here the reply from Gembox support

Try adding "System.Security.Permissions" package reference to your ".csproj" file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>  
  <ItemGroup>
    <PackageReference Include="GemBox.Spreadsheet" Version="45.0.1131" />
    <PackageReference Include="System.Security.Permissions" Version="4.7.0" />
  </ItemGroup>
</Project>

As an FYI, I believe that this package is only required for the Console application on Windows. It's not required when you're saving XLSX files with ASP.NET Core application on Windows or when you're saving XLSX files with any .NET Core application on Linux.

nomiso1183
  • 33
  • 5
0

It appears the package has a dependency on an assembly that isn't referenced or included.

Typically, a package author would reference their dependencies in their nuspec file for the Targetframework (each TargetFramework).


You can work around it by adding the latest System.Security.Permissions nuget package as a dependency to your project.


Update 1: Additionally

Looking at their example project github repo, I do see references to netcoreapp3.1 there.

I tested both netcoreapp3.1 and netcoreapp3.0, received the dependency package issue with Save, worked around it by adding it as a dependency (as this answer suggests). Gembox.Spreadsheet.Example

The example and usage of netcoreapp2.2 had no issues with missing dependencies of the package when attempting a Save.

Update 2

Removed reference to observed issue with Load mentioned in Update 1. It appears to be unrelated and probably a runtime and\or IDE issue I was experiencing.

Also, this issue was only tested and observed with a console application on windows platform.

Brett Caswell
  • 1,486
  • 1
  • 13
  • 25
  • actually, I don't see a netcoreapp3.1 nor netstandard2.1 targetframework support System.Security.Permission NuGet package... does gembox-spreadsheet package actually support netcoreapp3.1? – Brett Caswell Mar 25 '20 at 10:11
  • Good point. I just tested with .NET Core 3.0 and it causes the same error. – nomiso1183 Mar 25 '20 at 11:17
  • Basically, it's a bug that you should report to them @nomiso1183. – Ian Kemp Mar 25 '20 at 13:43