c# - netDxf 包 - System.IO.FileNotFoundException:'无法加载文件或程序集'System.Drawing.Common
问题描述
我正在尝试运行 netDXF 项目的 README 中列出的代码示例:https ://github.com/haplokuon/netDxf ,但代码在行上抛出以下异常DxfDocument dxf = new DxfDocument();
:
System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Drawing.Common, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.'
我遵循的步骤: 1. 我安装了 Visual Studio 2019 并创建了一个新项目,其“目标框架”值为“.NET core 3.0”,“输出类型”为“控制台应用程序”。2. 我已经通过右键单击我的项目并选择“管理 NuGet 包”来安装 netDXF 包,然后从那里安装 netDxf。3. 我运行了代码,看到了异常,并从 .netDxf 库中收集了以下堆栈跟踪:
netDxf.dll!netDxf.Tables.TextStyle.TextStyle(string name, string font, bool checkName) Unknown
netDxf.dll!netDxf.Tables.TextStyle.TextStyle(string name, string font) Unknown
netDxf.dll!netDxf.Tables.TextStyle.Default.get() Unknown
netDxf.dll!netDxf.DxfDocument.AddDefaultObjects() Unknown
netDxf.dll!netDxf.DxfDocument.DxfDocument(netDxf.Header.HeaderVariables drawingVariables, bool createDefaultObjects, System.Collections.Generic.IEnumerable<string> supportFolders) Unknown
netDxf.dll!netDxf.DxfDocument.DxfDocument(netDxf.Header.HeaderVariables drawingVariables) Unknown
netDxf.dll!netDxf.DxfDocument.DxfDocument() Unknown
> Mason.dll!Mason.Program.Main() Line 15 C#
这是我尝试运行的完整代码片段(Program.cs):
using netDxf;
using netDxf.Entities;
using netDxf.Header;
namespace Mason
{
class Program
{
public static void Main()
{
// your dxf file name
string file = "sample.dxf";
// by default it will create an AutoCad2000 DXF version
DxfDocument dxf = new DxfDocument();
// an entity
Line entity = new Line(new Vector2(5, 5), new Vector2(10, 5));
// add your entities here
dxf.AddEntity(entity);
// save to file
dxf.Save(file);
// this check is optional but recommended before loading a DXF file
bool isBinary;
DxfVersion dxfVersion = DxfDocument.CheckDxfFileVersion(file, out isBinary);
// netDxf is only compatible with AutoCad2000 and higher DXF version
if (dxfVersion < DxfVersion.AutoCad2000) return;
// load file
DxfDocument loaded = DxfDocument.Load(file);
}
}
}
解决方案
推荐阅读
- unity3d - 如果输入被垃圾邮件发送,Unity 动画属性将保持禁用状态
- python - Spark - “sc.parallelize()” 运行时间
- laravel - laravel 中用于多重身份验证的电子邮件验证
- asp.net-mvc - 什么是 ASP.Net MVC 中的 _Viewstart
- java - 应用程序启动方法 java.lang.reflect.InvocationTargetExceptio 中的异常
- python - 在 cx_Freeze 中编译后无法打开图像
- php - Symfony 根目录下 wordpress 博客的 Nginx 配置
- asp.net - ProfilePropertyLoader 属性
- c - 堆地址范围内全局变量的地址
- angular - 如何在需要用户确认的可观察对象上创建过滤器?