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

AccessViolationException when trying to set Block Property

4 REPLIES 4
Reply
Message 1 of 5
bert.vanpeteghem
487 Views, 4 Replies

AccessViolationException when trying to set Block Property

Hi,

I keep getting a AccessViolationException on various occasions on various block properties.

I'm not really able to post any code because the code base is simply too big, but the line in question goes as follows:

DynamicBlockReferenceProperty prop ...

prop.Value = "a value in correct Dxf type";

I know this is very little information to work with, but maybe someone would recognize this error or could give me any pointers of where to start looking...

Could this be caused by transactions, documents or anything not closed correctly?
4 REPLIES 4
Message 2 of 5

Curiosity lead me to visit the Cup o'Cad link in some of your other posts, and I think I might have seen a comment there where you found some info about this, but for what it's worth, most problems I have had with access violations have proven to be a result of transactions and/or objects not being closed/disposed properly. It can sometimes be a bear to track them down, since the spot in the code where the error occurs is often not the same spot as where the real problem is.

That said, the reason I did not reply to this post the first time I read it is because your example is a Dynamic bref property, and I have read various things about there being problems dealing with Dynamic blocks in .NET. Since I don't have any code of my own that deals with Dynamic blocks, I can't really comment on those issues. I figured someone else would chime in about that.
Dave O.                                                                  Sig-Logos32.png
Message 3 of 5

Bert -

While debugging, check the prop.PropertyTypeCode when the error occurs - maybe it's not the accurate type for your assignment?


I came across a similar problem when dealing with dynamic blocks that had their "Length"-property declared differently - sometimes as a double and sometimes as a string.

Here's a sample from my proj (2009):

if (dynProp.PropertyName == "Length")
{
if (dynProp.PropertyTypeCode == 40)
sLength = (string)dynProp.Value.ToString();
else
sLength = (string)dynProp.Value;
}
Message 4 of 5

Hi, thanks for the answer.

We do a pretty good check on every value that's being put in the dynamic properties. We've had problems with that before, so now everything gets casted to the right type immediately. So, I'm pretty sure that's not the answer.

Also, when debugging, the line - even before setting the value, when placing a watch on prop.Value it show the same Exception in the watch.

I said the exceptions showed up pretty randomly, and as chiefbraincloud says, it probably has something to do with transactions not being committed or objects that were not disposed properly.

Recently I read a blog post by Bobby C Jones (I think) and he says to always dispose Databases (when for example using ReadDwg ). I changed the code where that happens, and this error has not occurred since then.

So, I hope the problem is solved...
Message 5 of 5
SRSDS
in reply to: bert.vanpeteghem

This is a very old thread but I've just had the same problem.

Discovered that I needed to dispose the DynamicBlockReferencePropertyCollection.

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