首页 > 解决方案 > 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);
        }
    }
}

标签: c#dxf

解决方案


推荐阅读