Skip to content

Fix ASP0019: Replace Headers.Add with indexer syntax - #765

Merged
poppastring merged 2 commits into
mainfrom
copilot/fix-headers-argument-exception
Jan 19, 2026
Merged

poppastring merged 2 commits into
mainfrom
copilot/fix-headers-argument-exception

Conversation

Copilot AI commented Jan 19, 2026 •

Copy link
Copy Markdown
Contributor

The code uses IDictionary.Add() on IHeaderDictionary, which throws ArgumentException on duplicate keys. ASP.NET Core analyzer ASP0019 flags this pattern.

Changes

  • Replace context.Response.Headers.Add("Permissions-Policy", ...) with indexer syntax context.Response.Headers["Permissions-Policy"] = ... in Startup.cs:401

The indexer syntax safely replaces existing values instead of throwing on duplicates, which is the recommended approach per https://aka.ms/aspnet/analyzers.

Original prompt

This section details on the original issue you should resolve

<issue_title>Fix ASP0019: Use IHeaderDictionary.Append or indexer for headers, not IDictionary.Add</issue_title>
<issue_description>The code in DasBlog.Web (Startup.cs) uses IDictionary.Add to set headers, which can throw an ArgumentException if a duplicate key is added. Use IHeaderDictionary.Append or the indexer instead.

File:

  • DasBlog.Web.UI\Startup.cs (line 401)

Reference: https://aka.ms/aspnet/analyzers</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: poppastring <8739371+poppastring@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix ASP0019: Update header setting method in Startup.cs Fix ASP0019: Replace Headers.Add with indexer syntax Jan 19, 2026
Copilot AI requested a review from poppastring January 19, 2026 00:44
@poppastring
poppastring marked this pull request as ready for review January 19, 2026 00:49
@poppastring
poppastring merged commit 4f557c6 into main Jan 19, 2026
@poppastring
poppastring deleted the copilot/fix-headers-argument-exception branch January 19, 2026 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix ASP0019: Use IHeaderDictionary.Append or indexer for headers, not IDictionary.Add

2 participants