Dotnet watch throws exception in Docker Linux container
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
### Describe the Bug
When using `dotnet watch` the file polling throws following exception:
```
watch : Polling file watcher is enabled
watch : Started
Unhandled exception. System.ArgumentException: An item with the same key has already been added. Key: /src/Startup.cs
at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
at Microsoft.DotNet.Watcher.Internal.PollingFileWatcher.b__23_0(FileSystemInfo f)
at Microsoft.DotNet.Watcher.Internal.PollingFileWatcher.ForeachEntityInDirectory(DirectoryInfo dirInfo, Action`1 fileAction)
at Microsoft.DotNet.Watcher.Internal.PollingFileWatcher.CheckForChangedFiles()
at Microsoft.DotNet.Watcher.Internal.PollingFileWatcher.PollingLoop()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
```
### Steps to Reproduce
```bash
dotnet new web -f net5.0
```
Add [Directory.Build.props](https://github.com/dotnet/dotnet-docker/blob/main/samples/Directory.Build.props) to move `bin` and `obj`. The bug is however reproducible without this.
Make sure bin and obj are empty.
(on Windows)
```bash
docker run --rm -it -p 5000:80 -v ${pwd}:/src -w /src -e ASPNETCORE_URLS=http://+:80 -e ASPNETCORE_ENVIRONMENT=Development mcr.microsoft.com/dotnet/sdk:5.0 dotnet watch run --no-launch-profile
```
### Other Information
This only happens when the project hasn't been built yet. If I start the container with just `dotnet run` once, shut down the container, and then change back to `dotnet watch run` as entrypoint, it works.
This is reproducible with .NET 6 too.
### Output of `docker version`
20.10.10, build b485636
### Output of `docker info`
```
Client:
Context: default
Debug Mode: false
Plugins:
buildx: Build with BuildKit (Docker Inc., v0.6.3)
compose: Docker Compose (Docker Inc., v2.1.1)
scan: Docker Scan (Docker Inc., 0.9.0)
Server:
Containers: 3
Running: 0
Paused: 0
Stopped: 3
Images: 15
Server Version: 20.10.10
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runtime.v1.linux runc io.containerd.runc.v2
Default Runtime: runc
Init Binary: docker-init
containerd version: 5b46e404f6b9f661a205e28d59c982d3634148f8
runc version: v1.0.2-0-g52b36a2
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 5.10.60.1-microsoft-standard-WSL2
Operating System: Docker Desktop
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 12.42GiB
Name: docker-desktop
ID: IJEP:3W6Y:PWQF:KZOW:UBLU:PCJG:WOQ4:P2NB:B2ZP:TPMR:4PTD:BERP
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
```
Contributor guide
Assessment
This issue has not been assessed yet.