FileConfigurationProvider.Load throws InvalidDataException

When Load() fails to load a file, it throws an InvalidDataException. If the file or directory doesn't exist, it throws a DirectoryNotFoundException or FileNotFoundException.

Version introduced

6.0 RC 1

Previous behavior

When loading failed, Load() did not throw an InvalidDataException.

New behavior

Starting in .NET 6, Load() throws an InvalidDataException if a file fails to load. In addition, the exception message includes the file path that failed to load.

Type of breaking change

This change can affect source compatibility.

Reason for change

This change improves the debugging experience. When a file fails to load, it's helpful to know which file failed to load.

If you are catching specific exceptions when calling Load(), make sure to also catch InvalidDataException.

Affected APIs