You can use other overloads of Encoding.GetEncoding
to handle all cases when an Unicode character can't be converted to your target code page. More information on this MSDN topic.
The same could be achieved if you explicitly set the Encoding.EncoderFallback
property (link to MSDN).
For example you can use the following to throw an exception every time when conversion of one Unicode character fails:
Encoding enc = Encoding.GetEncoding(28605, EncoderFallback.ExceptionFallback, DecoderFallback.ExceptionFallback);
Note: The default EncoderFallback
is System.Text.InternalEncoderBestFitFallback
which produces question marks for unknown code points.