Assembly.GetType(string, bool, bool)
throws unexpected FileLoadException
on NET9
#113534
Labels
area-System.Reflection
binaryformatter-migration
Issues related to the removal of BinaryFormatter and migrations away from it
regression-from-last-release
Milestone
Description
When using
Assembly.GetType(string, bool, bool)
(in NET9) you can get unexpectedFileLoadException
depending on the input.Depending on the passed in string parameter the method either succeeds (or fails) to look up a type, or throws an exception. Throwing that exception under those circumstances is certainly unexpected.
According to the documentation a FileLoadException will occur when
alas - again according to the documentation,
Specifically this occurs when using
mscorlib
as assembly to call things on. That assembly certainly should NOT have a problem "loading".Reproduction Steps
Simple console program demonstrating the issue:
It seems, as soon as there are three (or more)
,
in thename
parameter the method invocation throws.Expected behavior
The method should certainly not throw a
FileLoadException
- because that indicates an issue with the probed assembly (here mscorlib) itself.It might be reasonable to throw an
ArgumentException
because at least the docs state that this might occuralthough "invalid" is not explained any further.
Preferably the method should not throw and just return
null
for a found type if the input is gibberish. Other runtimes - specifically NetFramework - simply returnednull
here.Actual behavior
The method throws an unexpected exception
FileLoadException
on certain parameters.Regression?
Yes. The method - and example code - will not throw an exception under previous versions of .NET (checked with .NET Framework 4.7.2 & .NET 8).
Known Workarounds
none
Configuration
NET 9.0.2
Other information
No response
The text was updated successfully, but these errors were encountered: