public void HandleFallback(ref EncoderFallbackBuffer buffer,
char[] chars, ref int charIndex, ref int charCount,
byte[] bytes, ref int byteIndex, ref int byteCount, object state)
{
if (buffer == null)
buffer = EncoderFallback.CreateFallbackBuffer();
// THIS IS WERE THE BUG IS!! (pruiz)
if (charCount > 1 && (Char.IsSurrogate(chars[charIndex]) && Char.IsSurrogate(chars[charIndex + 1])))
{
buffer.Fallback (chars[charIndex], chars[charIndex + 1], charIndex);
charIndex++;
charCount--;
}
else
buffer.Fallback (chars[charIndex], charIndex);
char[] tmp = new char[buffer.Remaining];
int idx = 0;
while (buffer.Remaining > 0)
tmp[idx++] = buffer.GetNextChar();
var len = state == null ?
GetBytes(tmp, 0, tmp.Length, bytes, byteIndex)
: GetBytesInternal(tmp, 0, tmp.Length, bytes, byteIndex, true, state);
byteIndex += len;
byteCount -= len;
}