Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, I am getting "System.AccessViolationException: Attempted to read or write protected memory." while trying go get layer of blockref in array.
Here is part of the code that give exeption, it always gives it then i try to get (obj as BlockReference).Layer, if i remove it, it works fine:
if (AssocArray.IsAssociativeArray(objectId))
{
using (BlockReference br = objectId.Open(OpenMode.ForRead) as BlockReference)
{
using (DBObjectCollection brs = new DBObjectCollection())
{
br.Explode(brs);
if (brs != null && brs.Count > 0)
{
foreach (DBObject obj in brs)
{
for (int j = 0; j < laylistBL.Length; j++)
{
if (obj is BlockReference && (obj as BlockReference).Layer == laylistBL[j])
{
TableValues[12 + j] += 1;
}
obj.Dispose();
}
}
}
}
}
}
I found similar code and modified it for myself here.
Can you please point out what I'm doing wrong?
Solved! Go to Solution.