Posts: 19
Registered: ‎10-23-2012
Message 1 of 3 (242 Views)
Accepted Solution

Fatal Error: Access Violation When Passing instance of Document To Another Class

242 Views, 2 Replies
10-23-2012 03:54 PM

I'm thinking this is by design, but a generic Fatal Error: Access Violation exception (which cannot be caught) is thrown and causes autocad to crash whenever I attempt to pass an instance of Document or Database to another classes method (a class other than the one which implements IApplicationExtension).


I've had trouble confirming this is by design and is something I just have to work around because AutoDesk restricts this using reflection or by some other means I do not comprehend. 


Specifically, I have subscribed to the DocumentManager's DocumentCreated event and I am attempting to pass the instance of the created document provided in the event argument object to an instance of a class I have defined which works with the Document's database but does not perminantly store a reference to the given Document object.


I'm using AutoCAD 2011 64-bit. 


Thanks for any help in advance. 

Active Member
Posts: 7
Registered: ‎09-22-2012
Message 2 of 3 (226 Views)

Re: Fatal Error: Access Violation When Passing instance of Document To Another C

10-24-2012 12:49 AM in reply to: kbrown

I don't think the errors you are receiving are by design, I regularly use the passing of Document arguments to cut up large functions into more managable methods. As long as you do not store the variable in a field you should be fine.


Do you develop in C# or VB? C# by default passes the argument as a reference to the actual data (VB ByRef) where VB's ByValue might cause an access violation because of the called function trying to copy the data.

Posts: 19
Registered: ‎10-23-2012
Message 3 of 3 (215 Views)

Re: Fatal Error: Access Violation When Passing instance of Document To Another C

10-24-2012 10:00 AM in reply to: vinkd

I did try your solution, and I thank you for the suggestion. However, passing by reference did not fix this issue. 


As a side note I am using vb.net (not my choice, my employers :'). After some trial and error I was able to solve the problem. I believe the problem was that the class I was passing the instance of Document to was derived from CollectionBase. I created a test class which was not derived from CollectionBase and the problem went away. So perhaps this was by design and the authors of this API were using reflection to prevent instances of certain types from being added to a collection. 


Thanks again for your help.

Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.