Remove use of unsafe code in the C# SDK