Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read with AcadSharp dwg file created with AcadSharp

See original GitHub issue

Describe the bug Cannot read with AcadSharp a dwg file written with AcadSharp.

To Reproduce I’ve created a dwg file with AcadSharp and then saved. All the documents section (such as the Header) are as default. When I try to load the file with DwgReader it throws the following exception: ACadSharp.Exceptions.DwgNotSupportedException: 'Dwg version not recognised.

Write dwg code:

// new document
ACadSharp.CadDocument doc = new ACadSharp.CadDocument();
// write file
ACadSharp.IO.DwgWriter writer = new ACadSharp.IO.DwgWriter("Test.dwg", doc);

Read dwg code:

ACadSharp.CadDocument loaded = ACadSharp.IO.DwgReader.Read("Test.dwg");

Full exception and stack trace: ACadSharp.Exceptions.DwgNotSupportedException: 'Dwg version not recognised

at ACadSharp.IO.DWG.DwgFileHeader.CreateFileHeader(ACadVersion version) in C:\Users\stage1\source\repos\ACadSharp\ACadSharp\IO\DWG\FileHeaders\DwgFileHeader.cs:line 37
at ACadSharp.IO.DwgReader.readFileHeader() in C:\Users\stage1\source\repos\ACadSharp\ACadSharp\IO\DWG\DwgReader.cs:line 225
at ACadSharp.IO.DwgReader.Read() in C:\Users\stage1\source\repos\ACadSharp\ACadSharp\IO\DWG\DwgReader.cs:line 97
at ACadSharp.IO.DwgReader.Read(String filename, DwgReaderConfiguration configuration, NotificationEventHandler notification) in C:\Users\stage1\source\repos\ACadSharp\ACadSharp\IO\DWG\DwgReader.cs:line 83
at ACadSharp.IO.DwgReader.Read(String filename, NotificationEventHandler notification) in C:\Users\stage1\source\repos\ACadSharp\ACadSharp\IO\DWG\DwgReader.cs:line 66

Expected behavior No exception

Screenshots From CadUtils: image It return AcadVersion.Unknown

Issue Analytics

  • State:closed
  • Created 6 months ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

DomCRcommented, Mar 27, 2023

perfect, I’ll open a branch to apply a fix to manually dispose the stream to avoid this issue in the future.

sv-edcommented, Mar 27, 2023

Well… yes, that worked, thank you 😃


This also solves the issue that the stream wasn’t closed successfully and the file resulted opened by another process, if I tried to open if after the write. Closing the program closed the stream too so the file was openable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DomCR/ACadSharp: C# library to read/write cad files like ...
C# library to read/write cad files like dxf/dwg. Contribute to DomCR/ACadSharp development by creating an account on GitHub.
Read more >
Free .NET Library for AutoCAD DXF & DWG Reading & Writing
ACadSharp – A powerful Open Source C# .NET Library allows software developers to open, read and write AutoCAD DXF & DWG drawings via...
Read more >
ACadSharp 1.0.1-alpha
C# library to read/write cad files like dxf/dwg. Compatible Dwg versions: DWG Release 1.1; DWG Release 1.2; DWG Release 1.4; DWG Release 2.0...
Read more >
"Value does not exist" (WW CadLib)
I have this code to try and read a DWG file into memory, so that I can read and manipulate the data. I...
Read more >
"DWG is currently in use or is read-only" when opening a ...
As a work-around, create a new folder and copy the DWG files into it, or resave the files into a new folder from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found