DwgWriter writes a null shape-file handle for SHAPE entities (WriteShapes = true)

Open Beginner friendly
#1,394 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.

  • #1407 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

Start in DwgObjectWriter.writeShape at the SHAPEFILE handle serialization cited in the issue, then trace how DwgObjectReader.readShape restores ShapeFileHandle and how Shape.ShapeStyle supplies it. Use the reproduction to write and read the sample DWG with WriteShapes = true; done means ShapeStyle remains unnamed1 after the round trip.

Written by the indexing model from the issue text.

Description

Describe the bug

With WriteShapes = true, DwgWriter writes SHAPE entities but always writes a null SHAPEFILE handle. The shape
loses its shape file, and Shape.ShapeStyle is null after the file is read back. DxfWriter keeps it.

To Reproduce

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

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

var doc = DwgReader.Read(Path.Combine(samples, "sample_AC1032.dwg"));
var shape = doc.GetCadObject<Shape>(0x889);
Console.WriteLine($"Read:  ShapeStyle = {shape.ShapeStyle?.Name ?? "null"} (shape file: {shape.ShapeStyle?.IsShapeFile})");

DwgWriter.Write("shape.dwg", doc, new DwgWriterConfiguration { WriteShapes = true });

var back = DwgReader.Read("shape.dwg");
shape = back.GetCadObject<Shape>(0x889);
Console.WriteLine($"After DWG round trip: ShapeStyle = {shape.ShapeStyle?.Name ?? "null"}");

Output:

Read:  ShapeStyle = unnamed1 (shape file: True)
After DWG round trip: ShapeStyle = null

Expected behavior

ShapeStyle is still unnamed1 after the round trip.

Additional context

DwgObjectWriter.writeShape writes HandleReference(DwgReferenceType.HardPointer, null) for the SHAPEFILE handle
(L2390-L2391).
DwgObjectReader.readShape reads that handle back into ShapeFileHandle. Writing shape.ShapeStyle there would
probably fix this. I haven't tested that.

A suggestion: when WriteShapes is false (the default), both writers skip shapes without a notification.
A NotImplemented notification, like the one DxfWriter raises for TableEntity, would let callers see that
something was left out.

The same code is on master (edf487a).


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.