DWG write at AC1015/AC1018/AC1024/AC1027 requires AutoCAD recovery on a no-op round-trip (AC1032 is clean; AC1021 throws)

Open
#1,323 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
csharp
Domain
backend, databases

Research direction

Start with DwgWriter.getFileHeaderWriter(), DwgFileHeaderWriterAC18, and the version conditionals in DwgSectionIO; compare section layouts for native files at each affected version. Validate round-trips in GUI AutoCAD, since accoreconsole.exe silently recovers the output. Done means supported versions open without recovery and AC1021 write support is clarified or implemented.

Written by the indexing model from the issue text.

Description

Summary

A no-op round-trip (read → write, no modification) produces DWG files that AutoCAD reports as needing recovery for every version except AC1032.

Source version DwgWriter.Write result AutoCAD
AC1015 (2000) writes "needs recovery"
AC1018 (2004) writes "needs recovery"
AC1021 (2007) throws CadNotSupportedException —
AC1024 (2010) writes "needs recovery"
AC1027 (2013) writes "needs recovery"
AC1032 (2018) writes opens clean

The file is not destroyed — AutoCAD's recovery succeeds and the drawing is usable afterwards. But every delivered file shows the recovery prompt, which is a blocker for batch processing.

Minimal reproduction

No proprietary files needed — any drawing works:

  1. In AutoCAD, create a drawing with a few TEXT and MTEXT entities. SAVEAS → 2010 (AC1024).
  2. Round-trip it, touching nothing:
var doc = DwgReader.Read("in.dwg");                  // version = AC1024
DwgWriter.Write("out.dwg", doc, new DwgWriterConfiguration());
  1. Open out.dwg in AutoCAD (GUI). It prompts to recover.
  2. Repeat with the same drawing saved as 2000 / 2004 / 2013 / 2018 — only the 2018 output opens without the prompt.

Expected: a no-op round-trip at any supported version produces a file AutoCAD opens without recovery.

Related observation: AC1021 cannot be written at all

DwgWriter.getFileHeaderWriter() has:

case ACadVersion.AC1021:
    throw new CadNotSupportedException(this._document.Header.Version);

Is this a permanent limitation or just not implemented yet? Writing AC1021 would fail even for a no-op round-trip, which makes the version ladder (R2000–R2018) incomplete on the write side.

Why this is easy to miss when testing

accoreconsole.exe silently performs the recovery and returns exit code 0, so a CLI-based round-trip test looks completely clean:

accoreconsole /i out.dwg /s script.scr   →  rc = 0, script runs normally

The problem only shows up in GUI AutoCAD, where the recovery prompt appears. Anyone validating writes headlessly (as I was) will conclude the output is fine.

Workaround I'm using

Forcing the header version before writing makes the output clean, because it stays on the AC1032 path and never enters the downgrade branches:

doc.Header.Version = ACadVersion.AC1032;
DwgWriter.Write(path, doc, config);

All of 2000/2004/2007/2010/2013 then write successfully and open clean — including AC1021, which no longer hits the throw. Side effect is that output is always 2018, which is not acceptable if downstream still uses older AutoCAD — hence this issue.

Guess at the cause

DwgFileHeaderWriterAC18 is shared by AC1018/AC1024/AC1027/AC1032 and looks like it's implemented against the 2018 layout, with DwgSectionIO's R2004Plus / R2007Plus / R2010Plus / R2013Plus / R2018Plus flags doing the subtraction for older targets. If any one of those conditionals is inverted or missing, the section layout ends up inconsistent with the version string in the header — which is exactly the kind of thing AutoCAD's recovery fixes quietly.

I haven't been able to narrow it to a specific field; that would need a section-by-section diff against a native file at each version.

Happy to test patches or provide more detail.

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.