Skip to content

Latest commit

 

History

History
29 lines (20 loc) · 1.64 KB

nullreferenceexception-exception-handling-code-from.md

File metadata and controls

29 lines (20 loc) · 1.64 KB

NullReferenceException in exception handling code from ImageSourceConverter.ConvertFrom

Details

An error in the exception handling code for xref:System.Windows.Media.ImageSourceConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext,System.Globalization.CultureInfo,System.Object) caused an incorrect xref:System.NullReferenceException?displayProperty=fullName to be thrown instead of the intended exception ( xref:System.IO.DirectoryNotFoundException?displayProperty=fullName or xref:System.IO.FileNotFoundException?displayProperty=fullName). This change corrects that error so that the method now throws the right exception.

By default all applications targeting .NET Framework 4.6.2 and earlier continue to throw xref:System.NullReferenceException?displayProperty=fullName for compatibility. Developers targeting .NET Framework 4.7 and above should see the right exceptions.

Suggestion

Developers who wish to revert to getting xref:System.NullReferenceException?displayProperty=fullName when targeting .NET Framework 4.7 or later can add/merge the following to their application's App.config file:

<configuration>
<runtime>
<AppContextSwitchOverrides value="Switch.System.Windows.Media.ImageSourceConverter.OverrideExceptionWithNullReferenceException=true"/>
</runtime>
</configuration>
Name Value
Scope Edge
Version 4.7
Type Retargeting

Affected APIs

  • xref:System.Windows.Media.ImageSourceConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext,System.Globalization.CultureInfo,System.Object)?displayProperty=nameWithType