Replace name with type and codepage in EncodingConversionOverflow exception#62910
Replace name with type and codepage in EncodingConversionOverflow exception#62910marek-safar merged 4 commits intodotnet:mainfrom
Conversation
…eptions Encoding name is virtual property that can throw during exception reporting. It also has large dependencies (~4k) on rarely used data.
|
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
Outdated
Show resolved
Hide resolved
|
Tagging subscribers to this area: @dotnet/area-system-text-encoding, @tarekgh Issue DetailsEncoding::name is virtual property that can throw during exception reporting. It also has large dependencies (~4k) on rarely used data.
|
| // This happens if user has implemented an encoder fallback with a broken GetMaxCharCount | ||
| throw new ArgumentException( | ||
| SR.Format(SR.Argument_EncodingConversionOverflowBytes, EncodingName, EncoderFallback.GetType()), "bytes"); | ||
| SR.Format(SR.Argument_EncodingConversionOverflowBytes, GetType(), _codePage, EncoderFallback.GetType()), "bytes"); |
There was a problem hiding this comment.
Is the concrete type returned from GetType() here going to be meaningful to consumers?
There was a problem hiding this comment.
As the type is abstract I believe so
There was a problem hiding this comment.
The type name will be very confusing and will not be helpful in most cases. Can we get the encoding name inside try-catch block to avoid throwing case? I am not expecting the encoding name to throw most of the time too. If we need to go with this change I would suggest at least get rid of the type name.
There was a problem hiding this comment.
Made an update with GetType out. This exception is rarely thrown and as mentioned in the description EncodingName has a surprisingly large dependency. I tried to simplify this corner case not to impact every .net app.
Encoding::name is virtual property that can throw during exception reporting. It also has large dependencies (~4k) on rarely used data.