# System.AccessViolationException VS Code Rhino Inside

**URL:** <https://discourse.mcneel.com/t/system-accessviolationexception-vs-code-rhino-inside/163068>\
**Category:** Rhino Developer\
**Tags:** windows, rhinocommon, python, rhino-inside\
**Created:** [July 20, 2023, 4:31pm UTC](https://discourse.mcneel.com/t/system-accessviolationexception-vs-code-rhino-inside/163068 "2023-07-20T16:31:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jobdvogel](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/jobdvogel/32/590519_2.png) [@jobdvogel](https://discourse.mcneel.com/u/jobdvogel)\
**Post date:** [July 20, 2023, 4:31pm UTC](https://discourse.mcneel.com/t/system-accessviolationexception-vs-code-rhino-inside/163068/1 "2023-07-20T16:31:19Z")

</div>

Hi,

After using the following line of Python code using Rhino.Inside Python in VS Code, I get an error after the script finishes. Could someone suggest how to fix this exception? I am not even sure if this line specifically causes the problem, but I noticed the script works fine when I skip this one.

```auto
centroids = [mesh.Faces.GetFaceCenter(i) for i in range(mesh.Faces.Count)]

```

Exception:

```auto
Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at Python.Runtime.Runtime.PyObject_TYPE(BorrowedReference op)
   at Python.Runtime.Runtime.NullGCHandles(IEnumerable`1 objects)
   at Python.Runtime.Runtime.TryCollectingGarbage(Int32 runs, Boolean forceBreakLoops)
   at Python.Runtime.Runtime.Shutdown()
   at Python.Runtime.PythonEngine.Shutdown()
   at Python.Runtime.Loader.Shutdown(IntPtr data, Int32 size)

```

Thank you for your time!!

---

<div class="post-metadata">

**Author:** ![jobdvogel](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/jobdvogel/32/590519_2.png) [@jobdvogel](https://discourse.mcneel.com/u/jobdvogel)\
**Post date:** [July 21, 2023, 3:19pm UTC](https://discourse.mcneel.com/t/system-accessviolationexception-vs-code-rhino-inside/163068/2 "2023-07-21T15:19:39Z")

</div>

Based on further inspection I do not expect this exception to be caused by the `GetFaceCenter` specifically. It seems to happen when I use other functions in a loop with a lot of iterations as well.
