c# - 为什么调用 Excelfile.save 时 Gembox 电子表格会崩溃:FileNotFoundException 无法加载文件或程序集 System.Security.Permissions
问题描述
我正在使用 Gembox 打开、修改和保存 xlsx 文件。对 Excelfile 调用 Save 会导致 System.IO.FileNotFoundException。
问题发生在我们公司的序列号和免费密钥上。
示例代码
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!
}
}
}
错误信息
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
堆栈跟踪
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
版本
- .NET Core 3.1(3.0 也失败)
- GemBox.Spreadsheet 版本=45.0.1131
- Visual Studio 2019 (VisualStudioVersion = 16.0.29905.134)
- Windows 10 专业版 64 位
示例 csproj 文件
<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>
解决方案
这里是 Gembox 支持的回复
尝试将“System.Security.Permissions”包引用添加到“.csproj”文件:
<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>
作为一个仅供参考,我相信这个包只需要 Windows 上的控制台应用程序。在 Windows 上使用 ASP.NET Core 应用程序保存 XLSX 文件或在 Linux 上使用任何 .NET Core 应用程序保存 XLSX 文件时,不需要它。
推荐阅读
- javascript - 为什么按名称删除项目的方法不起作用?
- python - PyCharm virtualenv 找不到正确的 python 二进制文件
- z3 - 使用 SMTLib for z3 的 Datalog 中的循环关系
- sql - 如何在oracle中按结果对两组求和
- java - 为什么我收到 javax.net.ssl.SSLException: Received fatal alert:protocol_version for ant?
- hive - 确定在 72 小时内至少在七个不同地点进行过交易的客户——Hive
- php - 将大数据从博主导入 WordPress
- java - Tomcat Websocket 禁用主机名验证
- python - 打开 CV cv.imread 修改图片
- c# - 规范化有符号值会产生 0 和 1 之外的值