Skip to content

Return false from TryGetCadObject when the object is not of the requested type - #1273

Merged
DomCR merged 2 commits into
DomCR:masterfrom
ilCosmico:fix/trygetcadobject-type
Oct 8, 2026
Merged

DomCR merged 2 commits into
DomCR:masterfrom
ilCosmico:fix/trygetcadobject-type

Conversation

@ilCosmico

Copy link
Copy Markdown
Contributor

CadDocument.TryGetCadObject<T> returned true with a null object when the handle belonged to an object of another type. BuildDataStorage relies on it, so since #1270 a DWG with an ACDS record that belongs to an entity that is not a ModelerGeometry throws a NullReferenceException and the whole read fails. I hit it on a 2013 DWG with REVOLVEDSURFACE entities, read with KeepUnknownEntities = true.

The method now checks the type, as the version in CadDocumentBuilder already does. Nothing in the repo relied on the old behavior.

I added two tests: the type mismatch on CadDocument, and BuildDataStorage with a record that points to an unknown surface entity, which threw before the fix.


namespace ACadSharp.Tests.Internal;

public class CadDocumentBuilderTests

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this one is needed, the functionality is tested in the local validation and the other reading tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in bd79b04.

@DomCR DomCR added the bug Something isn't working label Oct 8, 2026
@DomCR
DomCR merged commit 8f982b7 into DomCR:master Oct 8, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants