.NET

Reply
Active Contributor
xpeter88
Posts: 42
Registered: ‎11-14-2013
Message 1 of 13 (1,259 Views)
Accepted Solution

System.AccessViolationException: Attempted to read or write protected memory.

1259 Views, 12 Replies
02-05-2014 10:38 AM

Hi all,

I finished one code that opens the drawings does some changes in block tables and saves the updated drawings. Everything works perfectly as it should except this one error that I cannot figure out.

 

netload -> run my app -> it finishes -> and now when I close AutoCAD Application it gives me this error -> always the same and when I close AutoCAD App only.

 

Do you have any ideas where could be problem? Using AutoCAD 2012 and MS Visual Studio 2010.

Seems like something is still in memory and after I close AutoCAD app it tries to release from it.

 

Have you seen it before? Cannot identify where the issue starts as this message does not appear when I run the code.

 

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at Autodesk.AutoCAD.DatabaseServices.Transaction.CheckTopTransaction()
   at Autodesk.AutoCAD.DatabaseServices.Transaction.DeleteUnmanagedObject()
   at Autodesk.AutoCAD.Runtime.DisposableWrapper.!DisposableWrapper()
   at Autodesk.AutoCAD.Runtime.DisposableWrapper.Dispose(Boolean )


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34003 built by: FX45W81RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll
----------------------------------------
AdApplicationFrame
    Assembly Version: 0.0.0.0
    Win32 Version: 3.2.23.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AdApplicationFrame.DLL
----------------------------------------
Acdbmgd
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.51.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcdbMgd.DLL
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34003 built by: FX45W81RTMGDR
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
msvcm90
    Assembly Version: 9.0.30729.8387
    Win32 Version: 9.00.30729.8387
    CodeBase: file:///C:/WINDOWS/WinSxS/amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.8387_none_08e793bfa83a89b5/msvcm90.dll
----------------------------------------
AdWindows
    Assembly Version: 3.2.25.0
    Win32 Version: 3.2.25.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AdWindows.DLL
----------------------------------------
PresentationFramework
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34004
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework/v4.0_4.0.0.0__31bf3856ad364e35/PresentationFramework.dll
----------------------------------------
WindowsBase
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34004 built by: FX45W81RTMGDR
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/WindowsBase/v4.0_4.0.0.0__31bf3856ad364e35/WindowsBase.dll
----------------------------------------
PresentationCore
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34004 built by: FX45W81RTMGDR
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_64/PresentationCore/v4.0_4.0.0.0__31bf3856ad364e35/PresentationCore.dll
----------------------------------------
System.Xaml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Xaml/v4.0_4.0.0.0__b77a5c561934e089/System.Xaml.dll
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
PresentationFramework.Aero2
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework.Aero2/v4.0_4.0.0.0__31bf3856ad364e35/PresentationFramework.Aero2.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
Acmgd
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.205.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/Acmgd.DLL
----------------------------------------
System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
AcWindows
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.205.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcWindows.DLL
----------------------------------------
AcCui
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.51.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcCui.DLL
----------------------------------------
PresentationFramework.Aero
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework.Aero/v4.0_4.0.0.0__31bf3856ad364e35/PresentationFramework.Aero.dll
----------------------------------------
PresentationFramework-SystemXml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.33440
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework-SystemXml/v4.0_4.0.0.0__b77a5c561934e089/PresentationFramework-SystemXml.dll
----------------------------------------
WindowsFormsIntegration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34004 built by: FX45W81RTMGDR
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/WindowsFormsIntegration/v4.0_4.0.0.0__31bf3856ad364e35/WindowsFormsIntegration.dll
----------------------------------------
AcWindows.resources
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.51.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/en-US/AcWindows.resources.DLL
----------------------------------------
ContextualTabSelectorRules
    Assembly Version: 0.0.0.0
    Win32 Version: 18.2.205.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcWindows.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
ManagedMC3
    Assembly Version: 5.8.0.0
    Win32 Version: 5.8.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/ManagedMC3.DLL
----------------------------------------
PresentationFramework-SystemCore
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.33440
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework-SystemCore/v4.0_4.0.0.0__b77a5c561934e089/PresentationFramework-SystemCore.dll
----------------------------------------
UIAutomationTypes
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/UIAutomationTypes/v4.0_4.0.0.0__31bf3856ad364e35/UIAutomationTypes.dll
----------------------------------------
PresentationFramework.Luna
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework.Luna/v4.0_4.0.0.0__31bf3856ad364e35/PresentationFramework.Luna.dll
----------------------------------------
AcWelcomeScreen
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.51.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcWelcomeScreen.DLL
----------------------------------------
AcMrUi
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.51.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcMrUI.DLL
----------------------------------------
AcMrUi.resources
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.51.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/en-US/AcMrUi.resources.DLL
----------------------------------------
AcMr
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.51.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcMr.DLL
----------------------------------------
System.Runtime.Serialization
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Serialization/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Serialization.dll
----------------------------------------
AcLayer
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.51.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcLayer.DLL
----------------------------------------
AcLayer.resources
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.51.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/en-US/AcLayer.resources.DLL
----------------------------------------
AcButterflyExt
    Assembly Version: 1.0.0.23
    Win32 Version: 1.0.0.23
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcButterflyExt.DLL
----------------------------------------
AcButterflyExt.resources
    Assembly Version: 1.0.0.23
    Win32 Version: 1.0.0.23
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/en-US/AcButterflyExt.resources.DLL
----------------------------------------
UIAutomationProvider
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/UIAutomationProvider/v4.0_4.0.0.0__31bf3856ad364e35/UIAutomationProvider.dll
----------------------------------------
AcCommandToolTips
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.51.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcCommandToolTips.DLL
----------------------------------------
AcCommandToolTips.resources
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.51.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/en-US/AcCommandToolTips.resources.DLL
----------------------------------------
Connect.Client.AutoCAD
    Assembly Version: 2.0.90.0
    Win32 Version: 2.0.90.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/Connect.Client.AutoCAD.DLL
----------------------------------------
ATTRIBUTE_CHANGER
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/Gigo/Documents/Visual%20Studio%202010/Projects/ATTRIBUTE_CHANGER/ATTRIBUTE_CHANGER/bin/Debug/ATTRIBUTE_CHANGER.dll
----------------------------------------
Microsoft.VisualBasic
    Assembly Version: 10.0.0.0
    Win32 Version: 12.0.20806.33440 built by: FX45W81RTMREL
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
Microsoft.Office.Interop.Excel
    Assembly Version: 15.0.0.0
    Win32 Version: 15.0.4420.1017
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.Office.Interop.Excel/15.0.0.0__71e9bce111e9429c/Microsoft.Office.Interop.Excel.dll
----------------------------------------
office
    Assembly Version: 15.0.0.0
    Win32 Version: 15.0.4551.1009
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/office/15.0.0.0__71e9bce111e9429c/office.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

 

 

 

New Member
3dmathe2sowmin
Posts: 2
Registered: ‎07-30-2013
Message 2 of 13 (1,252 Views)

Re: System.AccessViolationException: Attempted to read or write protected memory

02-05-2014 11:03 AM in reply to: xpeter88

hi

 

i am interpreting the error as System.AccessViolation is of as guessed memory that is not free during closure of program. for get going i came out with fear for text as line. Area to look at 

 

System.Permission, some folder settings change as i could think of. 

 

 

Valued Mentor
gasty1001
Posts: 445
Registered: ‎04-11-2010
Message 3 of 13 (1,243 Views)

Re: System.AccessViolationException: Attempted to read or write protected memory

02-05-2014 11:19 AM in reply to: xpeter88

Hi,

 

This ATTRIBUTE_CHANGER.dll is my main suspect, i guess it's not disposing attributes references.

 

Gaston Nunez

Active Contributor
xpeter88
Posts: 42
Registered: ‎11-14-2013
Message 4 of 13 (1,231 Views)

Re: System.AccessViolationException: Attempted to read or write protected memory

02-05-2014 12:19 PM in reply to: gasty1001

I am using this for attribute definitions

 

Dim acAttDef As AttributeDefinition = acTrans.GetObject(acEntity.ObjectId, OpenMode.ForWrite)

 

some oprerations here

 

and acAttDef.Dispose is there as well for attribute definitions.

 

If you mean this..

 

Do you think that the issue with the disposing objects?

Valued Mentor
gasty1001
Posts: 445
Registered: ‎04-11-2010
Message 5 of 13 (1,226 Views)

Re: System.AccessViolationException: Attempted to read or write protected memory

02-05-2014 12:29 PM in reply to: xpeter88

Hi,

 

Only guessing...without code to inspect.

 

Gaston Nunez

Valued Mentor
gasty1001
Posts: 445
Registered: ‎04-11-2010
Message 6 of 13 (1,223 Views)

Re: System.AccessViolationException: Attempted to read or write protected memory

02-05-2014 12:40 PM in reply to: xpeter88

Hi,

 

Not sure what are you trying to do, but if you aim is to set attributes values, you don't have to open for write the attributes definition. This is a way to go with attributes:

 

Public Shared Sub SetAttValue(ByVal blkRef As BlockReference, ByVal attributeTag As String, ByVal AttValueAs String, ByVal tr As Transaction)
        Dim btr As BlockTableRecord = DirectCast(tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead), BlockTableRecord)
        For Each attId As ObjectId In btr
            Dim ent As Entity = DirectCast(tr.GetObject(attId, OpenMode.ForRead), Entity)
            If TypeOf ent Is AttributeDefinition Then
                Dim attDef As AttributeDefinition = DirectCast(ent, AttributeDefinition)
                Dim attRef As New AttributeReference()
                attRef.SetAttributeFromBlock(attDef, blkRef.BlockTransform)
                If attRef.Tag = attributeTag.ToUpper Then
                    attRef.TextString = AttValue
                    Dim id As ObjectId = blkRef.AttributeCollection.AppendAttribute(attRef)
                    tr.AddNewlyCreatedDBObject(attRef, True)
                End If
                attRef.Dispose()
            End If
        Next
    End Sub

 Gaston Nunez

Active Contributor
xpeter88
Posts: 42
Registered: ‎11-14-2013
Message 7 of 13 (1,218 Views)

Re: System.AccessViolationException: Attempted to read or write protected memory

02-05-2014 12:46 PM in reply to: 3dmathe2sowmin
 @3dmathe2sowmin: I did not get you at all
Active Contributor
xpeter88
Posts: 42
Registered: ‎11-14-2013
Message 8 of 13 (1,207 Views)

Re: System.AccessViolationException: Attempted to read or write protected memory

02-05-2014 01:24 PM in reply to: gasty1001

Gasty, I don't think I am doing this wrong check this.

 

I am not updating attribute references of blocks but values of attribute definitions that are not nested in blocks based on it's tag.

 

Using acTrans As Transaction = acNewDwgDb.TransactionManager.StartTransaction()
                                        Dim acBlkTbl As BlockTable = acTrans.GetObject(acNewDwgDb.BlockTableId, OpenMode.ForRead)
                                        Dim acBlkTblRec As BlockTableRecord = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
                                        Dim acObjId As ObjectId
                                        For Each acObjId In acBlkTblRec                                            
                                            Dim acEntity As Entity = acTrans.GetObject(acObjId, OpenMode.ForWrite)                                           
                                            If (TypeOf acEntity Is AttributeDefinition) Then                                               
                                                Dim acAttDef As AttributeDefinition = acTrans.GetObject(acEntity.ObjectId, OpenMode.ForWrite)                                              
                                                If acAttDef.Tag.ToUpper = AttributeTag Then
                                                    acAttDef.UpgradeOpen()
                                                    If acAttDef.IsWriteEnabled = True Then                                                        
                                                            acAttDef.TextString = AttributeValue  
                                                    End If                                                    
                                                    acEntity.Dispose()
                                                End If
                                            End If
                                        Next
                                        acTrans.Commit()
                                        acTrans.Dispose()
                                    End Using

 

Mentor
mzakiralam
Posts: 229
Registered: ‎11-09-2012
Message 9 of 13 (1,200 Views)

Re: System.AccessViolationException: Attempted to read or write protected memory

02-05-2014 03:09 PM in reply to: xpeter88

Hi ,

don't dispose transaction before end using. With end using transaction will be disposed automatically. first you have disposed the transaction and at the end of end using, it is trying to dispose transaction again. just remove the  line "acTrans.Dispose()" and try again with your code.

New Member
3dmathe2sowmin
Posts: 2
Registered: ‎07-30-2013
Message 10 of 13 (1,187 Views)

Re: System.AccessViolationException: Attempted to read or write protected memory

02-05-2014 05:12 PM in reply to: xpeter88

Firstly i vaguely understood System.AccessViolationException as attempt to read or write data in the memory location that is not meant for a particular user. so in my particular thread i asked as small suggestion that could point you to look at permission to read-write data in network tab. 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
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 to get help installing your software.

Ask the Community