Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

FileConfigurationProvider: Handle and forward IO exceptions to OnLoadException - #126093

#126093
Merged
mrek-msft merged 35 commits into
dotnet:maindotnet/runtime:mainfrom
mrek-msft:dev/mrek/mefs-filecfgprov-reload-lockedmrek-msft/runtime:dev/mrek/mefs-filecfgprov-reload-lockedCopy head branch name to clipboard
Jul 27, 2026
Merged

FileConfigurationProvider: Handle and forward IO exceptions to OnLoadException#126093
mrek-msft merged 35 commits into
dotnet:maindotnet/runtime:mainfrom
mrek-msft:dev/mrek/mefs-filecfgprov-reload-lockedmrek-msft/runtime:dev/mrek/mefs-filecfgprov-reload-lockedCopy head branch name to clipboard

Conversation

@mrek-msft

@mrek-msft mrek-msft commented Mar 25, 2026

Copy link
Copy Markdown
Member

Current behavior of FileConfigurationProvider on various types of failures at various times:

First Load OnChange Reload
data parsing failure OnLoadException callback is called
AddJsonFile throws

OnLoadException callback is called
program continues
no reload happen
IO failure on file open AddJsonFile throws Silent
program continues
no reload happen
possibly raises UnobservedTaskException later

This PR unifies it in a way that both types of failure behave same as data parsing failure.

This brings some behavioral changes

  • OnLoadException callback is newly triggered if IO error happen on both types of events (first load, reload)
  • UnobservedTaskException can no longer be observed in scenario when user registers OnLoadException callback. It can however happen when no callback is registered, so XML comment on OnLoadException was updated.
  • OnLoadException callbacks now receives not only InvalidDataException, but also IOException (or any other exception which (possibly custom) implementation of IFileProvider can throw). If user cast to InvalidDataException, he may miss other exceptions or get cast exceptions.

Based on follow up Copilot code reviews, I did few more behavior changes at edge cases, they do not relate directly to issue and can be reverted independently if not desired.

  • OnReload() now fires only when Data actually changed. Previously on first load, if a parse or IO error occurred and OnLoadException set Ignore = true, OnReload() was fired unconditionally even though Data was never modified. The new code fires OnReload() only when Data was successfully loaded or explicitly cleared (e.g., on reload or optional missing file). For consecutive reloads with parse errors, Data is cleared and OnReload() still fires. This change is independent on original fix and can be reverted independently if not desirable.

Fix #113964

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Unifies FileConfigurationProvider failure handling so IO failures during file open are handled the same way as parsing failures with respect to OnLoadException (including on reload-on-change), preventing unobserved/unhandled exceptions like the one reported in #113964.

Changes:

  • Moves stream opening (OpenRead) inside the exception-handling region so IO errors are routed through HandleException/OnLoadException.
  • Adds an inner try/catch to wrap exceptions thrown by Load(stream) in an InvalidDataException with the standard “Failed to load…” message.
  • Adjusts the outer catch to forward the exception through HandleException (enabling ignore behavior on reload).

@mrek-msft
mrek-msft marked this pull request as draft March 25, 2026 15:36
Copilot AI review requested due to automatic review settings March 26, 2026 16:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

Copilot AI review requested due to automatic review settings March 26, 2026 16:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

Copilot AI review requested due to automatic review settings March 27, 2026 10:48
Copilot AI review requested due to automatic review settings April 21, 2026 13:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

@tarekgh tarekgh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left minor comments I hope you address them. LGTM, otherwise.

@mrek-msft
mrek-msft marked this pull request as draft May 14, 2026 12:12
@mrek-msft
mrek-msft marked this pull request as ready for review July 27, 2026 14:11
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@mrek-msft mrek-msft added the breaking-change Issue or PR that represents a breaking API or functional change over a previous release. label Jul 27, 2026
@dotnet-policy-service dotnet-policy-service Bot added the needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet label Jul 27, 2026
@dotnet-policy-service

dotnet-policy-service Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Added needs-breaking-change-doc-created label because this PR has the breaking-change label.

When you commit this breaking change:

  1. Create and link to this PR and the issue a matching issue in the dotnet/docs repo using the breaking change documentation template, then remove this needs-breaking-change-doc-created label.
  2. Ask a committer to mail the .NET Breaking Change Notification DL.

Tagging @dotnet/compat for awareness of the breaking change.

@mrek-msft

Copy link
Copy Markdown
Member Author

/backport to release/11.0-preview7

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0-preview7 (link to workflow run)

@github-actions

Copy link
Copy Markdown
Contributor

@mrek-msft backporting to release/11.0-preview7 failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Forward IO exceptions to OnLoadException
Applying: Removed duplicate Data dict recreation
Applying: Add tests
Applying: Throw alaways InvalidDataException and clear Data only on data error.
Applying: Improve test attributes assignment.
Applying: Fix typos
Applying: Change exception back to rpopagating IOException directly and improve file path formatting logic.
Applying: Fix missing PhysicalPath in error string shown file name selection
Applying: Improve comment.
Applying: Remove duplicate test.
Applying: Add missing ActiveIssue attribute to possibly flaky test.
Applying: Add comment recommended by Copilot
Applying: Check for type of observed exception.
Applying: Dispose IConfigurationRoot
Applying: Update comment and its location based on Copilot hints
Applying: Do not fire OnReload if no Data change happened.
Applying: Add checking config value after faulty reload
Applying: Move and improve comment.
Applying: Fix double empty line
Applying: Add docs mentioning consequences of not registering OnLoadException.
Applying: Improve test coverage to handle Copilot discovered edge cases
Applying: exclude IOException from handling on "parse error" path.
Applying: Improve comment
Applying: Improve comment
Applying: Fix comment grammar
Applying: Improve FileLoadExceptionContext.Exception comment as requested in PR review
Applying: Removal of nested try..catch and handling deletion explicitly
Applying: Handle file not found in the same way on both paths.
Applying: Fix whitespace formatting
Applying: Copilot improved comment
Applying: Removed old comment
Applying: Fix typo in comment
Applying: Propagate DirectoryNotFoundException properly.
error: sha1 information is lacking or useless (src/libraries/Microsoft.Extensions.Configuration.FileExtensions/src/FileConfigurationProvider.cs).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0033 Propagate DirectoryNotFoundException properly.
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

@mrek-msft mrek-msft removed the needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet label Jul 27, 2026
mrek-msft added a commit that referenced this pull request Jul 27, 2026
… IO exceptions to OnLoadException (#131427)

Backport of #126093 to release/11.0-preview7

## Customer Impact

Long standing issue reported by customer

- [X] Customer reported
- [ ] Found internally

## Regression

Long standing issue.

- [ ] Yes
- [X] No

## Testing

6 tests were added.

## Risk

Low. It is backport to Preview 7 version after branch were snapped but
before code complete.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@dotnet-milestone-bot dotnet-milestone-bot Bot modified the milestones: 11.0.0, 11.0-rc1 Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Extensions-FileSystem breaking-change Issue or PR that represents a breaking API or functional change over a previous release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unhandled exception from FileConfigurationProvider when re-loading a locked file

6 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.