Skip to content

Fix NullReferenceException in LocalizationModelDeserializer for malformed keys - #9470

Merged
marcpopMSFT merged 4 commits into
mainfrom
copilot/fix-null-reference-exception
Nov 4, 2025
Merged

marcpopMSFT merged 4 commits into
mainfrom
copilot/fix-null-reference-exception

Conversation

Copilot AI commented Oct 28, 2025 •

Copy link
Copy Markdown

Malformed localization keys cause NullReferenceException in LoadPostActionModels and LoadManualInstructionModels. Keys like "postActions/" or "postActions/pa0/manualInstructions//text" result in null/empty values after splitting that are assigned to non-nullable string variables.

Changes

  • Added null/empty checks in LoadPostActionModels and LoadManualInstructionModels before using grouped keys
  • Mirrors existing defensive pattern in LoadSymbolModels and LoadChoiceModels
  • Added test coverage for malformed keys in all three key types (postActions, manualInstructions, symbols)
foreach (var postActionParts in strings.GroupBy(p => p.NameParts.FirstOrDefault()))
{
    if (string.IsNullOrEmpty(postActionParts.Key))
    {
        // Post action with no ID. Ignore.
        continue;
    }
    
    string postActionId = postActionParts.Key;
    // ... continue processing
}

Malformed keys are now silently skipped instead of throwing exceptions.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • c50vsblobprodcus330.vsblob.vsassets.io
    • Triggering command: ./.dotnet/dotnet build src/Microsoft.TemplateEngine.Orchestrator.RunnableProjects/Microsoft.TemplateEngine.Orchestrator.RunnableProjects.csproj (dns block)
    • Triggering command: ./.dotnet/dotnet restore src/Microsoft.TemplateEngine.Orchestrator.RunnableProjects/Microsoft.TemplateEngine.Orchestrator.RunnableProjects.csproj --force --force-evaluate (dns block)
    • Triggering command: /home/REDACTED/work/templating/templating/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/templating/templating/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/templating/templating/artifacts/toolset/11.0.0-beta.25527.104.txt (dns block)
  • securitytools.pkgs.visualstudio.com
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.23.1/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.TemplateEngine.Orchestrator.RunnableProjects.LocalizationModelDeserializer.<>c.b__4_4(ValueTuple`2 s)


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

Copilot AI and others added 3 commits October 28, 2025 21:01
Add null checks in LoadPostActionModels and LoadManualInstructionModels methods to prevent NullReferenceException when processing malformed localization keys. Also add test cases to validate the fix.

Co-authored-by: marcpopMSFT <[email protected]>
Copilot AI changed the title [WIP] Fix NullReferenceException in localization model deserializer Fix NullReferenceException in LocalizationModelDeserializer for malformed keys Oct 28, 2025
Copilot AI requested a review from marcpopMSFT October 28, 2025 21:11
@marcpopMSFT

Copy link
Copy Markdown
Member

Original report: https://developercommunity.visualstudio.com/t/NullReferenceException-in-LoadPostAction/10971178
@Evangelink does updating your post action help solve it on your side?
@baronfel is ignoring an empty postaction key the behavior you'd want? You know the template engine better than I.

@Evangelink

Copy link
Copy Markdown
Member

Sorry it's too long ago I don't really recall. I know that after my fixes things were working for my tests in SDK but we had to revert because post actions were not supported in VS and leading to template crashing.

@baronfel

Copy link
Copy Markdown
Member

At run-time I'm happy with this. I think the template engine has an authoring-focused NuGet Package that provides helpers - it would be awesome if at build-time these keys could be validated in some way.

@marcpopMSFT
marcpopMSFT marked this pull request as ready for review October 30, 2025 18:21
@marcpopMSFT
marcpopMSFT requested a review from a team as a code owner October 30, 2025 18:21
@marcpopMSFT
marcpopMSFT requested a review from baronfel October 30, 2025 18:21
@marcpopMSFT

Copy link
Copy Markdown
Member

I didn't do any validation of this change as I'm not as familiar with this repo. I just scanned the code for where it was making the change and it's description of the change which seemed to be no longer failing at runtime with an empty postaction but rather just skipping it.

@marcpopMSFT

Copy link
Copy Markdown
Member

/backport to release/10.0.2xx

@github-actions

github-actions Bot commented Nov 4, 2025

Copy link
Copy Markdown

Started backporting to release/10.0.2xx (link to workflow run)

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.

4 participants