.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
kbrown
529 Views, 2 Replies

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

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. 

2 REPLIES 2
Message 2 of 3
vinkd
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.

Message 3 of 3
kbrown
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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost