我正在尝试为NETDXF项目运行自述文件中列出的代码示例: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.通过右键单击我的项目并选择“ Manage NuGet Packages”,然后从那里安装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);
}
}
}