Description
As part of #47228 i am running an analyzer to detect APIs throwing PNSE but not annotated with Obsolete/SupportedOSPlatform/UnsupportedOSPlatform attributes, we need to annotate them so that developers get warnings when they use them unexpectedly
For now, I have results only cross-platform and .Net 5.0 or higher builds, analysis of targeted builds or lower env are coming soon where more APIs could be detected
API | Comment | Suggestion | Location |
---|---|---|---|
'Assembly.ReflectionOnlyLoad(byte[])' | unconditionally throws on all platforms | add [Obsolete] | libraries\System.Private.CoreLib\src\System\Reflection\Assembly.cs(376,73) |
'Assembly.ReflectionOnlyLoad(string)' | unconditionally throws on all platforms | add [Obsolete] | libraries\System.Private.CoreLib\src\System\Reflection\Assembly.cs(378,76) |
'Assembly.ReflectionOnlyLoadFrom(string)' | unconditionally throws on all platforms | add [Obsolete] | libraries\System.Private.CoreLib\src\System\Reflection\Assembly.cs(380,78) |
'StrongNameKeyPair.StrongNameKeyPair(string)' | unconditionally throws on all platforms | add [Obsolete] | libraries\System.Private.CoreLib\src\System\Reflection\StrongNameKeyPair.cs(33,13) |
'StrongNameKeyPair.PublicKey.get' | unconditionally throws on all platforms | add [Obsolete] | libraries\System.Private.CoreLib\src\System\Reflection\StrongNameKeyPair.cs(36,13) |
'Type.ReflectionOnlyGetType(string, bool, bool)' | unconditionally throws on all platforms | add [Obsolete] | libraries\System.Private.CoreLib\src\System\Type.cs(544,110) |
'Activator.CreateInstance(Type, BindingFlags, Binder?, object?[]?, CultureInfo?, object?[]?)' | throws with non platform related condition | consider changing the exception to NotSupportedException | libraries\System.Private.CoreLib\src\System\Activator.RuntimeType.cs(33,17) |
Note: We are suggesting to add [Obsolete] with the corresponding message for APIs supported in .Net framework but not supported in .NetCore, if it is only supported on a specific platform(s) consider adding [SupportedOSPlatform("platformName")] or if it is unsupported on a specific platform(s) [UnsupportedOSPlatform("platformName")] attribute instead
Suggestions for changing the exception is optional