Skip to content

[net11] Templates: Fix duplicate Empty/empty parameter crash in maui-blazor templates#34609

Merged
mattleibow merged 3 commits intonet11.0from
copilot/fix-templates-and-build
Mar 25, 2026
Merged

[net11] Templates: Fix duplicate Empty/empty parameter crash in maui-blazor templates#34609
mattleibow merged 3 commits intonet11.0from
copilot/fix-templates-and-build

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 23, 2026

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Root Cause

The maui-blazor and maui-blazor-web template.json files defined two symbols with effectively the same name: Empty (PascalCase) and empty (lowercase). This was intentional when added in #32227Empty was kept as a hidden backward-compat alias for users who had used the old CLI flag.

However, .NET 11's templating engine now performs case-insensitive key comparison when loading template symbols, causing it to throw:

System.ArgumentException: An item with the same key has already been added. Key: empty

This makes dotnet new maui-blazor and dotnet new maui-blazor-web completely broken.

Description of Change

  • maui-blazor/.template.config/template.json: Remove the duplicate "Empty" (PascalCase) parameter block.
  • maui-blazor-solution/.template.config/template.json: Remove the duplicate "Empty" (PascalCase) parameter block.
  • SampleContent computed expression (both files): Simplified from (!Empty && ...) && (!empty && ...) to just !empty && ... since the Empty alias is gone.

No other templates were found to have duplicate case-insensitive parameter keys.

Issues Fixed

Related: dotnet/templating#10025


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Removes a case-insensitive duplicate template parameter (Empty vs empty) from the MAUI Blazor templates to prevent System.ArgumentException failures in newer .NET SDK templating when parsing template.json.

Changes:

  • Removed the deprecated Empty boolean parameter from both Blazor template template.json files.
  • Updated the SampleContent computed symbol expressions to rely only on empty for dotnet CLI hosts.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Templates/src/templates/maui-blazor/.template.config/template.json Removes Empty symbol and updates SampleContent computed expression to use only empty.
src/Templates/src/templates/maui-blazor-solution/.template.config/template.json Removes Empty symbol and updates SampleContent computed expression to use only empty.
Comments suppressed due to low confidence (2)

src/Templates/src/templates/maui-blazor/.template.config/template.json:173

  • Empty was removed from this template’s symbols, but src/Templates/src/templates/maui-blazor/.template.config/dotnetcli.host.json still contains symbolInfo for Empty. That entry is now stale and can be removed to keep the CLI host configuration aligned with the template’s symbols (and avoid future confusion about whether --Empty is supported).
    "empty": {
      "type": "parameter",
      "datatype": "bool",
      "defaultValue": "false",
      "description": "Configures whether to omit sample pages and styling that demonstrate basic usage patterns."

src/Templates/src/templates/maui-blazor-solution/.template.config/template.json:411

  • Empty was removed from this template’s symbols, but src/Templates/src/templates/maui-blazor-solution/.template.config/dotnetcli.host.json still contains symbolInfo for Empty. That entry is now stale and can be removed to keep the CLI host configuration aligned with the template’s symbols (and avoid future confusion about whether --Empty is supported).
    "empty": {
      "type": "parameter",
      "datatype": "bool",
      "defaultValue": "false",
      "description": "Configures whether to omit sample pages and styling that demonstrate basic usage patterns."

@mattleibow mattleibow changed the base branch from main to net11.0 March 23, 2026 22:27
@mattleibow mattleibow force-pushed the copilot/fix-templates-and-build branch from 7566d3e to bce0075 Compare March 23, 2026 22:29
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 23, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 34609

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 34609"

@mattleibow mattleibow changed the title Fix duplicate Empty/empty parameters in MAUI Blazor template.json files [net11] Templates: Fix duplicate Empty/empty parameter crash in maui-blazor templates Mar 23, 2026
@mattleibow mattleibow marked this pull request as ready for review March 24, 2026 18:03
@mattleibow mattleibow requested a review from Copilot March 24, 2026 18:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/Templates/src/templates/maui-blazor-solution/.template.config/template.json:412

  • After removing the Empty symbol, the template’s localization files still contain symbols/Empty/description entries but no symbols/empty/description. This can leave the --empty parameter without localized help text (or cause stale localization keys to linger). Regenerate/update .template.config/localize/templatestrings*.json so the description is keyed to empty.
    "IncludeSampleContent": {
      "type": "parameter",
      "datatype": "bool",
      "defaultValue": "true",
      "displayName": "_Include sample pages",
      "description": "Configures whether to add sample pages and styling to demonstrate basic usage patterns."
    },
    "empty": {
      "type": "parameter",
      "datatype": "bool",
      "defaultValue": "false",
      "description": "Configures whether to omit sample pages and styling that demonstrate basic usage patterns."
    },

Comment on lines 162 to 174
"IncludeSampleContent": {
"type": "parameter",
"datatype": "bool",
"defaultValue": "true",
"displayName": "_Include sample pages",
"description": "Configures whether to add sample pages and styling to demonstrate basic usage patterns."
},
"Empty": {
"type": "parameter",
"datatype": "bool",
"defaultValue": "false",
"description": "Configures whether to omit sample pages and styling that demonstrate basic usage patterns."
},
"empty": {
"type": "parameter",
"datatype": "bool",
"defaultValue": "false",
"description": "Configures whether to omit sample pages and styling that demonstrate basic usage patterns."
},
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After removing the Empty symbol, the template’s localization files still only define symbols/Empty/description (and there is no symbols/empty/description). This likely means the --empty option’s description won’t be localized (or will be looked up under a stale key). Regenerate/update the .template.config/localize/templatestrings*.json entries to use the empty symbol key instead of Empty.

Copilot uses AI. Check for mistakes.
@mattleibow
Copy link
Copy Markdown
Member

⚠️ Merge Conflict Detected — This PR has merge conflicts with its target branch. Please rebase onto the target branch and resolve the conflicts.

Copilot AI and others added 3 commits March 24, 2026 21:49
The Empty parameter was removed from template.json but references
remained in the dotnetcli.host.json files for both maui-blazor and
maui-blazor-solution templates.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Rename the localization key to match the remaining lowercase 'empty'
parameter after the PascalCase 'Empty' duplicate was removed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mattleibow mattleibow force-pushed the copilot/fix-templates-and-build branch from e22344e to 9ce8709 Compare March 24, 2026 19:49
@mattleibow
Copy link
Copy Markdown
Member

⚠️ Merge Conflict Detected — This PR has merge conflicts with its target branch. Please rebase onto the target branch and resolve the conflicts.

@mattleibow mattleibow merged commit 3deb096 into net11.0 Mar 25, 2026
26 of 31 checks passed
@mattleibow mattleibow deleted the copilot/fix-templates-and-build branch March 25, 2026 15:10
@mattleibow
Copy link
Copy Markdown
Member

/backport to release/11.0.1xx-preview3

@github-actions
Copy link
Copy Markdown
Contributor

Started backporting to release/11.0.1xx-preview3 (link to workflow run)

mattleibow added a commit that referenced this pull request Mar 25, 2026
…pty parameter crash in maui-blazor templates (#34646)

Backport of #34609 to release/11.0.1xx-preview3

/cc @mattleibow @Copilot

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: mattleibow <1096616+mattleibow@users.noreply.github.com>
Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

3 participants