private static byte[] TerminateUtf8(byte[] utf8) { if (utf8.Length > 0 && utf8[utf8.Length - 1] == 0) return utf8; var termedArray = new byte[utf8.Length + 1]; Array.Copy(utf8, termedArray, utf8.Length); termedArray[utf8.Length] = 0; return termedArray; }