DwgReader reads a color-book entity's Color as ByBlock instead of the book's color

Open Beginner friendly
#1,392 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

@menes97 is already working on this.

Since Nov 17, 2026.

  • #1409 by @menes97 — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
csharp
Domain
backend

Research direction

Read DwgStreamReaderAC18.ReadEnColor and CadEntityTemplate.Build, which the issue identifies as the placeholder and BookColor resolution paths. Compare how the DWG reader assigns Entity.Color with the DXF result for the supplied sample files. Done means DwgReader reports the book color's RGB as Entity.Color across the listed DWG versions, while retaining the correct BookColor.

Written by the indexing model from the issue text.

Description

Describe the bug

For an entity with a color-book color, DwgReader sets Entity.Color to ByBlock. Entity.BookColor is
read correctly, and its Color holds the real RGB. AutoCAD shows the entity in that color, and DxfReader
returns it as Entity.Color for the same entity in the DXF version of the sample.

To Reproduce

using ACadSharp;
using ACadSharp.Entities;
using ACadSharp.IO;

string samples = args.Length > 0 ? args[0] : "samples";

var fromDxf = DxfReader.Read(Path.Combine(samples, "sample_AC1032_ascii.dxf"));
var c = fromDxf.GetCadObject<Circle>(0x99F);
Console.WriteLine($"DXF  sample_AC1032_ascii.dxf: Color = {c.Color}, BookColor = {c.BookColor?.Name} ({c.BookColor?.Color})");

foreach (var file in new[] { "sample_AC1018.dwg", "sample_AC1032.dwg" })
{
	var fromDwg = DwgReader.Read(Path.Combine(samples, file));
	c = fromDwg.GetCadObject<Circle>(0x99F);
	Console.WriteLine($"DWG  {file}: Color = {c.Color}, BookColor = {c.BookColor?.Name} ({c.BookColor?.Color})");
}

Output:

DXF  sample_AC1032_ascii.dxf: Color = True Color RGB:226,144,0, BookColor = RAL CLASSIC$RAL 1006 (True Color RGB:226,144,0)
DWG  sample_AC1018.dwg: Color = ByBlock, BookColor = RAL CLASSIC$RAL 1006 (True Color RGB:226,144,0)
DWG  sample_AC1032.dwg: Color = ByBlock, BookColor = RAL CLASSIC$RAL 1006 (True Color RGB:226,144,0)

sample_AC1021.dwg, sample_AC1024.dwg and sample_AC1027.dwg give the same result.

Expected behavior

Entity.Color is True Color RGB:226,144,0, which is the book color's color, as DxfReader returns.

Additional context

DwgStreamReaderAC18.ReadEnColor returns Color.ByBlock as a placeholder when flag 0x4000 is set
(L74-L79).
CadEntityTemplate.Build then resolves the BookColor from its handle
(L102-L106),
but never copies BookColor.Color into Entity.Color. Copying it there would probably fix this. I haven't tested that.

The same code is on master (edf487a). See also #1391 (DwgWriter writes an unreadable entity when it has both a true color and a BookColor).


Release needed

  • Yes, using the Nuget package.
  • No, using the github repo.
Dominant language
C#
Stars
873
Forks
223
Avg merge
1d 15h
Merged PRs (30d)
28

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DomCR/ACadSharp

All issues in DomCR/ACadSharp

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.