dotnet / dotnet/runtime

PhysicalFileProvider.UsePollingFileWatcher returns false after polling watcher initialization

Open Beginner friendly
#131,871 1 comment 0 reactions 0 assignees View on GitHub
area-Extensions-FileSystem
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Description

## Description

`PhysicalFileProvider.UsePollingFileWatcher` reports `false` after the file watcher has been initialized, even when the initialized watcher is using polling.

The getter currently contains:

```csharp
if (_fileWatcher != null)
{
return false;
}
```

This conflicts with the property's documentation (and its name), which says it determines whether the provider "uses polling to determine file changes."

## Reproduction

```csharp
using var provider = new PhysicalFileProvider(root)
{
UsePollingFileWatcher = true,
};

_ = provider.Watch("appsettings.json"); // Initializes the watcher.

Console.WriteLine(provider.UsePollingFileWatcher); // False
```

The same misleading result occurs on platforms where `PhysicalFileProvider` automatically falls back to polling.

## Expected behavior

`UsePollingFileWatcher` should continue to report whether the initialized provider uses polling. Once `_fileWatcher` is initialized, its internal `PollForChanges` property contains the effective value, so the getter could return it:

```csharp
if (_fileWatcher is not null)
{
return _fileWatcher.PollForChanges;
}
```

This would not change the setter's existing behavior: attempting to modify the setting after initialization would still throw.

## History

The getter originally threw after initialization. #36397 reported that property getters should not throw, and dotnet/extensions#2099 changed the getter to return `false`. Reviewers explicitly retained that behavior, but the discussion did not address the resulting inaccurate value when polling was enabled.

> [!NOTE]
> This issue was drafted with GitHub Copilot.

Contributor guide

Open the contributing guide

Research direction

Start at the PhysicalFileProvider.UsePollingFileWatcher getter and the _fileWatcher initialization described in the issue. Reproduce the behavior with Watch("appsettings.json"), then verify that the getter reports the initialized watcher's PollForChanges value while the existing post-initialization setter behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
operating-systems
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.