Fixes an error causes System.AccessViolationException

Fixes an error causes System.AccessViolationException