Skip to content

Commit

Permalink
Add innerException to ResourceReader FileNotFoundException (#72957)
Browse files Browse the repository at this point in the history
Co-authored-by: Dan Moseley <[email protected]>
  • Loading branch information
joperezr and danmoseley authored Aug 5, 2022
1 parent 2ad7b1a commit 4b7f748
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,10 @@ private Type UseReflectionToGetType(int typeIndex)
Debug.Assert(_typeTable[typeIndex] != null, "Should have found a type!");
return _typeTable[typeIndex]!;
}
// If-defing this coud out from Resources Extensions since they will by definition always support deserialization
// So we shouldn't attempt to wrap the original exception with a NotSupportedException since that can be misleading.
// For that reason, the bellow code is only relevant when building CoreLib's ResourceReader.
#if !RESOURCES_EXTENSIONS
// If serialization isn't supported, we convert FileNotFoundException to
// NotSupportedException for consistency with v2. This is a corner-case, but the
// idea is that we want to give the user a more accurate error message. Even if
Expand All @@ -981,10 +985,12 @@ private Type UseReflectionToGetType(int typeIndex)
//
// We don't want to regress the expected case by checking the type info before
// getting to Type.GetType -- this is costly with v1 resource formats.
catch (FileNotFoundException)
catch (FileNotFoundException fileNotFoundException) when (!_permitDeserialization)
{
throw new NotSupportedException(SR.NotSupported_ResourceObjectSerialization);
// Include the FileNotFoundException as an inner exception to make it more diagnosable
throw new NotSupportedException(SR.NotSupported_ResourceObjectSerialization, fileNotFoundException);
}
#endif
finally
{
_store.BaseStream.Position = oldPos;
Expand Down

0 comments on commit 4b7f748

Please sign in to comment.