Fix to Allow an Encoder Fallback with UTF8

This week I'll be running a series covering fixes for WCF that may be hard to find and explaining the details behind each problem.

Encoding is the process of transforming a set of characters into a sequence of bytes. An encoder fallback is an error-handling mechanism invoked when a character can't be fully converted or represented. Similarly, decoding is the process of transforming a sequence of bytes into a set of characters and a decoder fallback is an error-handling mechanism invoked during that process.

Two standard encoder fallback implementations are to throw an exception when an input character cannot be encoded, called an exception fallback, and to substitute a sequence of characters in place of an input character that cannot be encoded, called a replacement fallback. You can write your own fallback implementation and configure these fallbacks as part of defining the character encoding.

The original code for the WCF text encoder didn't preserve the configured fallback when the character set was UTF8. The UTF8 encoding web name was special cased as part of an optimization. Since the default encoder fallback implementation was an exception fallback, an exception would always be thrown for unconvertible characters regardless of the fallback implementation configured.

After installing this fix you're able to customize the fallback implementation even when using the UTF8 character set with the text encoding.

This fix is available for download from KB article 967090.