# RhinoInside python script terminal error when read and write

**URL:** <https://discourse.mcneel.com/t/rhinoinside-python-script-terminal-error-when-read-and-write/126034>\
**Category:** Rhino.Inside\
**Created:** [June 16, 2021, 10:33am UTC](https://discourse.mcneel.com/t/rhinoinside-python-script-terminal-error-when-read-and-write/126034 "2021-06-16T10:33:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ugur](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/ugur/32/311276_2.png) [@ugur](https://discourse.mcneel.com/u/ugur)\
**Post date:** [June 16, 2021, 10:33am UTC](https://discourse.mcneel.com/t/rhinoinside-python-script-terminal-error-when-read-and-write/126034/1 "2021-06-16T10:33:41Z")

</div>

Hello forum members,  
When I run the script, I am getting an this error. It is especially when I read the 3dm file, I came across this error.

```auto
C:\Users\fited\Desktop\python-rhino-script>python -m rhinoInsideTest2

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at UnsafeNativeMethods.CRhinoDoc_Delete(UInt32 serialNumber)
   at Rhino.RhinoDoc.Finalize()

```

my script is

```auto
mport rhinoinside
rhinoinside.load()
import Rhino
import os
import time

# input file path
inputFile = r'C:\Users\fited\Downloads\2021_06_07_Brace_Model.3dm'

# get the template file path
templateFile = Rhino.ApplicationSettings.FileSettings.TemplateFile
rhinoDoc = Rhino.RhinoDoc.CreateHeadless(templateFile)
Rhino.RhinoDoc.ActiveDoc = rhinoDoc
Rhino.Commands.CommandStyleAttribute(2)
rhinoDoc.Import(inputFile)
time.sleep(10)
Rhino.RhinoApp.RunScript('_-GrasshopperPlayer 2021_03_11_Brace_Generation_Script.gh',False)
time.sleep(5)
Rhino.RhinoApp.RunScript(' -exit N _-Enter',False)

```

---

<div class="post-metadata">

**Author:** ![ugur](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/ugur/32/311276_2.png) [@ugur](https://discourse.mcneel.com/u/ugur)\
**Post date:** [June 24, 2021, 11:08am UTC](https://discourse.mcneel.com/t/rhinoinside-python-script-terminal-error-when-read-and-write/126034/2 "2021-06-24T11:08:10Z")

</div>

Is there any suggestion for this problem?

---

<div class="post-metadata">

**Author:** ![stevebaer](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/stevebaer/32/473567_2.png) [@stevebaer](https://discourse.mcneel.com/u/stevebaer)\
**Post date:** [August 31, 2021, 9:56pm UTC](https://discourse.mcneel.com/t/rhinoinside-python-script-terminal-error-when-read-and-write/126034/3 "2021-08-31T21:56:05Z")

</div>

Try calling `rhinoDoc.Dispose()` at the end of your script.

---

<div class="post-metadata">

**Author:** ![ugur](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/ugur/32/311276_2.png) [@ugur](https://discourse.mcneel.com/u/ugur)\
**Post date:** [September 29, 2021, 1:47pm UTC](https://discourse.mcneel.com/t/rhinoinside-python-script-terminal-error-when-read-and-write/126034/4 "2021-09-29T13:47:38Z")

</div>

Thank you Steve. When I wrote the rhinoDoc.Dispose(), there was no error. But grasshopper plugin not worked. I used GetPlugInObject and OpenDocument with grasshopper file but grasshopper file did not applied on my 3dm file. What should I do?

```auto
pluginObject = Rhino.RhinoApp.GetPlugInObject("Grasshopper")

```
