Author Topic: AutoCAD 2020 and Random System.AccessViolationExceptions  (Read 468 times)

0 Members and 1 Guest are viewing this topic.

lCine7ic

  • Mosquito
  • Posts: 7
AutoCAD 2020 and Random System.AccessViolationExceptions
« on: March 05, 2020, 10:06:14 AM »
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



It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7000
  • AKA Daniel
Re: AutoCAD 2020 and Random System.AccessViolationExceptions
« Reply #1 on: March 06, 2020, 08:53:33 AM »
Do you mean while the debugger is attached?

lCine7ic

  • Mosquito
  • Posts: 7
Re: AutoCAD 2020 and Random System.AccessViolationExceptions
« Reply #2 on: March 06, 2020, 11:47:21 AM »
Yes -
Do you mean while the debugger is attached?
Yes -- the System.AccessViolationException exceptions occur seemingly randomly with the Debugger attached.  Oddly enough, running the Addin without the Debugger attached allows the addin to startup / initialize completely, and then, without failing throws the System.AccessViolationException exception seemingly as soon as the program becomes quiescent.

Bryco

  • Water Moccasin
  • Posts: 1851
Re: AutoCAD 2020 and Random System.AccessViolationExceptions
« Reply #3 on: March 06, 2020, 07:11:03 PM »
Is there any document lock in there?  As I have seen that work then not work

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7000
  • AKA Daniel
Re: AutoCAD 2020 and Random System.AccessViolationExceptions
« Reply #4 on: March 06, 2020, 08:04:51 PM »
Managed debugger has issues, but if your getting exceptions without the debugger attached, then its more than likely your code. I would start by adding a logger in your try..catch, (if you can catch it) output the message and the stack, this should help narrow things down.

nobody

  • Swamp Rat
  • Posts: 816
  • .net stuff
Re: AutoCAD 2020 and Random System.AccessViolationExceptions
« Reply #5 on: March 08, 2020, 03:07:53 AM »
Nothing to do with this but curious what framework you in?

lCine7ic

  • Mosquito
  • Posts: 7
Re: AutoCAD 2020 and Random System.AccessViolationExceptions
« Reply #6 on: March 09, 2020, 09:33:05 AM »
Nothing to do with this but curious what framework you in?

It is targeting 4.7.1.

I notice when building, the Build log includes:
Build started 3/16/2020 6:22:42 PM.
5>CoreResGen:
5>  "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\resgen.exe" /useSourcePath...

Could it be that it is using the wrong verison of resgen.exe (the NETFX 4.6.1 as opposed to the 4.7.1)?

« Last Edit: March 16, 2020, 06:28:01 PM by lCine7ic »

lCine7ic

  • Mosquito
  • Posts: 7
Re: AutoCAD 2020 and Random System.AccessViolationExceptions
« Reply #7 on: March 09, 2020, 09:49:33 AM »
Managed debugger has issues, but if your getting exceptions without the debugger attached, then its more than likely your code. I would start by adding a logger in your try..catch, (if you can catch it) output the message and the stack, this should help narrow things down.
Indeed, there is a Try Catch block attempting to catch a System.Exception wrapping the code in the CommandMethod Method.

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7000
  • AKA Daniel
Re: AutoCAD 2020 and Random System.AccessViolationExceptions
« Reply #8 on: March 09, 2020, 07:49:19 PM »
Have you looked into the [HandleProcessCorruptedStateExceptions] attribute?

lCine7ic

  • Mosquito
  • Posts: 7
Re: AutoCAD 2020 and Random System.AccessViolationExceptions
« Reply #9 on: March 10, 2020, 01:15:03 PM »
Have you looked into the [HandleProcessCorruptedStateExceptions] attribute?

No -- I will look into this - thank you for the suggestion!

lCine7ic

  • Mosquito
  • Posts: 7
Re: AutoCAD 2020 and Random System.AccessViolationExceptions
« Reply #10 on: March 16, 2020, 06:20:06 PM »
Have you looked into the [HandleProcessCorruptedStateExceptions] attribute?

No -- I will look into this - thank you for the suggestion!

I added the [HandleProcessCorruptedStateExceptions] and the [SecurityCritical] Attributes to my Command (which the contents are entirely wrapped in a try / catch [System.Exception] block) but that does not seem to help.

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7000
  • AKA Daniel
Re: AutoCAD 2020 and Random System.AccessViolationExceptions
« Reply #11 on: March 30, 2020, 12:37:38 AM »
If you can find a way to post a sample solution that reproduces the issue, someone might be able to spot the problem.

lCine7ic

  • Mosquito
  • Posts: 7
Re: AutoCAD 2020 and Random System.AccessViolationExceptions
« Reply #12 on: Today at 09:30:15 AM »
If you can find a way to post a sample solution that reproduces the issue, someone might be able to spot the problem.

It is WAYYY to large to generalize ;)

So I uninstalled / re-installed AutoCAD 2020 and discovered something weird.

When I run my addin w/o the debugger, I now get an 'AutoCAD Error Aborting' window with a 'Fatal Error: Unhandled Access Violation' popup.  However, as long as I do NOT click 'OK' to close the pop-up, I can still use AutoCAD.  My ToolTip handlers work, my custom commands work, I can switch between various paperspace tabs...

This REALLY leads me to believe that the problem is w/ perhaps one of the new AutoCAD 2020 features --  maybe related to cloud storage which I am not using but is perhaps putting some sort of exclusive document lock.

It didn't behave this way before the re-install; before it would immediately go straight to the AutoDesk Error reporting app.