dotnet-serve
dotnet-serve copied to clipboard
System.ArgumentException: An item with the same key has already been added. Key: Cross-Origin-Embedder-Policy
Describe the bug I want to add two headers so that SharedArrayBuffer can be enabled on the JavaScript side so I set up the .netconfig file as follow:
[serve]
header = Cross-Origin-Embedder-Policy: require-corp
header = Cross-Origin-Opener-Policy: same-origin
Sometimes it works, sometimes it doesn't work. Error message: System.ArgumentException: An item with the same key has already been added. Key: Cross-Origin-Embedder-Policy
To Reproduce Steps to reproduce the behavior: Environment: Ubuntu 22
- Run
dotnet serve - Or run
dotnet serve --headers "Cross-Origin-Embedder-Policy:require-corp" --headers "Cross-Origin-Opener-Policy:same-origin"
You can just test this repo in Github codespace: https://github.com/Jasonlhy/emcc-playground
Environment Windows 11
- Run
dotnet serveis fine without facing any issues, it can also add the two headers - Run
dotnet serve --headers "Cross-Origin-Embedder-Policy:require-corp" --headers "Cross-Origin-Opener-Policy:same-origin"will face the same issue
Workaround
Run dotnet serve .netconfig
Expected behavior Two headers should be added successfully without facing any error
Screenshots

None of the code in this project adds this header. Have you checked if there is something happening automatically in the ASP.NET Core framework itself? I did a quick search and see a few issues mentioning this header, https://github.com/dotnet/aspnetcore/search?q=Cross-Origin-Embedder-Policy&type=issues.
This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please comment if you believe this should remain open, otherwise it will be closed in 14 days. Thank you for your contributions to this project.
Closing due to inactivity. If you are looking at this issue in the future and think it should be reopened, please make a commented here and mention natemcmaster so he sees the notification.