dotnet / dotnet/dotnet-api-docs

System.Reflection.Metadata throws BadImageFormatException on bad input

Open
#8,526 8 comments 0 reactions 0 assignees View on GitHub
area-System.Reflection.Metadata Pri3
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

If a user passes in a bad handle, for instance they get an `ExportedTypeHandle` from one MetadataReader instance's `MetadataReader.ExportedTypes`, and pass it to a different MetadataReader instance via `MetadataReader.GetExportedType` we will throw `BadImageFormatException`. This is unintuitive since both images are fine and the problem was with the *argument* passed to `GetExportedType`. We should probably be throwing something derived from `ArgumentException`, like `ArgumentOutOfRangeException` or something similar.

/cc @nguerrera @tmat

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.