I'm attempting to set the DecoderFallback property of an arbitrary (but supported) encoding in my C# app. Essentially what i'm trying to do is this:
ASCIIEncoding ascii = new ASCIIEncoding();
ascii.DecoderFallback = new DecoderExceptionFallback();
I'm getting an exception i've never seen before:
System.InvalidOperationException was unhandled Message="Instance is read-only." Source="mscorlib"
StackTrace: at System.Text.Encoding.set_DecoderFallback(DecoderFallback value) at <... into my app...> InnerException:
I was unable to find any MSDN documenation with examples of how to use that property. If anyone could point me to some maybe suggest what is wrong my usage I'd appreciate it. I need to throw an exception upon failure to decode a byte or bytes and cannot afford to let that go unnoticed.
Thanks, brian
This property is read-only. You need to use Encoding.GetEncoding() to create your own encode with your configs. This method receive the encode, the EncoderFallback and the DecoderFallback.
var enc = System.Text.Encoding.GetEncoding("ASCII", EncoderFallback.ExceptionFallback, DecoderFallback.ExceptionFallback);
http://msdn.microsoft.com/pt-br/library/89856k4b.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With