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

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

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
xpeter88
18526 Views, 12 Replies

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

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.

 

 

 

12 REPLIES 12
Message 2 of 13
3dmathe2sowmin
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. 

 

 

Tags (1)
Message 3 of 13
hgasty1001
in reply to: xpeter88

Hi,

 

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

 

Gaston Nunez

Message 4 of 13
xpeter88
in reply to: hgasty1001

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?

Message 5 of 13
hgasty1001
in reply to: xpeter88

Hi,

 

Only guessing...without code to inspect.

 

Gaston Nunez

Message 6 of 13
hgasty1001
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

Message 7 of 13
xpeter88
in reply to: 3dmathe2sowmin

 @3dmathe2sowmin: I did not get you at all
Message 8 of 13
xpeter88
in reply to: hgasty1001

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

 

Message 9 of 13
mzakiralam
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.

Message 10 of 13
3dmathe2sowmin
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. 

Message 11 of 13
xpeter88
in reply to: mzakiralam

@mzakiralam: thanks, I did not know that as I am quite new to the .net. I will remember that and try it out as soon as I get home. I've just posted the "core", it is not all I have, there is open folder dialog, reading excel file, writes some text files etc etc, I will check it all if I did not make this misstake somewhere else too and let you know here.

Message 12 of 13
xpeter88
in reply to: mzakiralam

Checked my code and to remove acTrans.Dispose() did not help at all. There no more cases like this.

Can be the problem with some of the referenced *.dll's? I have a similar code that is mostly the same like this - no special differences just less references and works fine.

 

Message 13 of 13
xpeter88
in reply to: xpeter88

Public Class MyCommands
        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Database = acDoc.Database
        Dim acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
        <CommandMethod("myspecialcommand")>

 

This was the issue between the class and commendmethod.... probably did a copy paste misstake and did not see it in in all the lines of code.

 

Dim acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

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