AutoCAD 2020 and Random System.AccessViolationException

AutoCAD 2020 and Random System.AccessViolationException

Heard_chris
Explorer Explorer
582 Views
2 Replies
Message 1 of 3

AutoCAD 2020 and Random System.AccessViolationException

Heard_chris
Explorer
Explorer

Hi,

I've been working on a .Net Addin since AutoCAD 2009 and have been adapting/extending it over the years to work with the various versions of AutoCAD I've used (AutoCAD 2013, 2016, 2018 and now 2020).

It has run as expected in all versions until 2020.  Granted, there have been Exceptions thrown over the time but always due to errors in my code and acted predictably.  By predictably, I mean if there was an exception thrown, then unless I resolved it, it would continue to be thrown at the same line of code.

With AutoCAD 2020, I'm getting System.AccessViolationException thrown at different points of execution with really nothing else changing.  I have Visual Studio set to Debug the addin by running AutoCAD 2020 and opening a specific drawing file.  After that, I type a simple command to load the .Net Addin which goes through a set of initialization procedures for the drawing (loading blocks, initializing layouts, etc), BUT will ultimately terminate with a System.AccessViolationException at some point.  I'm not saving the file or anything along the way so I'd expect two consecutive Debug Runs to terminate at the same place, but it doesn't.  Heck, I've seen it throw the Exception when simply trying to Create a new XmlSerializer based on a custom Serialized class that I KNOW works.  It doesn't make ANY sense!

Funny thing is, the addin still works fine when ran in AutoCAD 2018.

Has anyone had similar issues?

Any recommendations?!  Any feedback you can provide is TRULY appreciated.

Best Regards,
Chris

0 Likes
583 Views
2 Replies
Replies (2)
Message 2 of 3

Heard_chris
Explorer
Explorer

All,

I know this is an old topic, but I've recently had the opportunity to do a bit more digging and have some more leads.  If you have the time, please take a look and let me know if there is a solution.

I enabled the extended debugger features and noticed that the failure always occurred in thread other than the 'MAIN' thread.  The methods being called are:
Acdbmgd.dll!Autodesk.AutoCAD.DatabaseServices.DynamicBlockReferencePropertyCollection.DeleteUnmanagedObject()
Acdbmgd.dll!<Module>.AcArray<AcDbDynBlockReferenceProperty,AcArrayObjectCopyReallocator<AcDbDynBlockReferenceProperty> >.setPhysicalLength(AcArray<AcDbDynBlockReferenceProperty,AcArrayObjectCopyReallocator<AcDbDynBlockReferenceProperty> >*, int)  - < crash occurs in this method;

This made me think it was a Dynamic Block Issue. 
I removed the vast majority of the dynamic blocks that were imported into the drawing at startup, leaving only 1.  CRASH.
I created a static version of the remaining Dynamic block and ran the plugin.  No CRASH.
I replaced the static version back with the Dynamic block and ran the plugin.  CRASH.
I swapped out this dynamic block with another dynamic block (still only importing 1).  CRASH.
Before running the addin, I inserted the Dynamic Block and so that it had 1 active (non-purged) Block Reference and ran the Addin.  NO CRASH
Before running the addin, I inserted the Dynamic Block and so that it had 1 active (non-purged) Block Reference.  I then deleted the Block Reference but did not purge.  I then ran the Addin.  CRASH.

If you have any ideas on how to resolve this, please let me know.

Best Regards

Message 3 of 3

Anton_Huizinga
Advocate
Advocate

Thanks for your update! Today it was helpful to me in a situation where I got the System.AccessViolationException when saving XRecords in the NOD in AutoCAD 2021 and 2022, but not in 2023 and up.

Your post hinted to the use of Dynamic Blocks. Indeed my function inserted a dynamic block prior to the XRecord action, to read the visibility states. As soon as I used a non-dynamic block, the XRecord was saved as expected, without an Exception.

 

Thanks 🙂

0 Likes