Fixes an error causes AccessViolationException

Fixes an error causes System.AccessViolationException