Skip to content

[release/11.0-preview7] FileConfigurationProvider: Handle and forward IO exceptions to OnLoadException - #131427

Merged
mrek-msft merged 1 commit into
dotnet:release/11.0-preview7from
mrek-msft:dev/mrek/mefs-filecfgprov-reload-locked-backport-p7
Jul 27, 2026
Merged

[release/11.0-preview7] FileConfigurationProvider: Handle and forward IO exceptions to OnLoadException#131427
mrek-msft merged 1 commit into
dotnet:release/11.0-preview7from
mrek-msft:dev/mrek/mefs-filecfgprov-reload-locked-backport-p7

Conversation

@mrek-msft

Copy link
Copy Markdown
Member

Backport of #126093 to release/11.0-preview7

Customer Impact

Long standing issue reported by customer

  • Customer reported
  • Found internally

Regression

Long standing issue.

  • Yes
  • No

Testing

6 tests were added.

Risk

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

…Exception (dotnet#126093)

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

|  | First Load | OnChange Reload |
|---|---|---|
| data parsing failure | `OnLoadException` callback is
called<br>`AddJsonFile` throws<br><br> | `OnLoadException` callback is
called<br>program continues<br>no reload happen |
| IO failure on file open | `AddJsonFile` throws | Silent<br>program
continues<br>no reload happen<br>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 dotnet#113964

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@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

Copy link
Copy Markdown
Member Author

/ba-g Only unrelated known iOS errors

@mrek-msft

Copy link
Copy Markdown
Member Author

Adding servicing-approved. Based on discussion in tactics email, since it is not code complete yet, no servicing approval is needed.

@mrek-msft mrek-msft added the Servicing-approved Approved for servicing release label Jul 27, 2026
@mrek-msft
mrek-msft merged commit 253bde0 into dotnet:release/11.0-preview7 Jul 27, 2026
91 of 96 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants