Conversation
`FirstOrDefault` can return null, so it's not safe to dereference unconditionally. Observed while debugging VS: ``` System.NullReferenceException: Object reference not set to an instance of an object. Microsoft.TemplateEngine.Orchestrator.RunnableProjects.LocalizationModelDeserializer.LoadPostActionModels.AnonymousMethod__4_4((System.Collections.Generic.IEnumerable<string> NameParts, string LocalizedString) s) System.Linq.Enumerable.WhereSelectEnumerableIterator<(System.Collections.Generic.IEnumerable<string>, string), (System.Collections.Generic.IEnumerable<string>, string)>.MoveNext() System.Linq.Lookup<string, (System.Collections.Generic.IEnumerable<string>, string)>.Create<(System.Collections.Generic.IEnumerable<string>, string)>(System.Collections.Generic.IEnumerable<(System.Collections.Generic.IEnumerable<string>, string)> source, System.Func<(System.Collections.Generic.IEnumerable<string>, string), string> keySelector, System.Func<(System.Collections.Generic.IEnumerable<string>, string), (System.Collections.Generic.IEnumerable<string>, string)> elementSelector, System.Collections.Generic.IEqualityComparer<string> comparer) System.Linq.GroupedEnumerable<(System.Collections.Generic.IEnumerable<string>, string), string, (System.Collections.Generic.IEnumerable<string>, string)>.GetEnumerator() Microsoft.TemplateEngine.Orchestrator.RunnableProjects.LocalizationModelDeserializer.LoadManualInstructionModels(System.Collections.Generic.IEnumerable<(System.Collections.Generic.IEnumerable<string> NameParts, string LocalizedString)> strings) Microsoft.TemplateEngine.Orchestrator.RunnableProjects.LocalizationModelDeserializer.LoadPostActionModels(System.Collections.Generic.List<(string Key, string Value)> localizedStrings) Microsoft.TemplateEngine.Orchestrator.RunnableProjects.LocalizationModelDeserializer.Deserialize(Microsoft.TemplateEngine.Abstractions.Mount.IFile file) Microsoft.TemplateEngine.Orchestrator.RunnableProjects.ScannedTemplateInfo.FindLocalizations() Microsoft.TemplateEngine.Orchestrator.RunnableProjects.ScannedTemplateInfo.ScannedTemplateInfo(Microsoft.TemplateEngine.Abstractions.IEngineEnvironmentSettings settings, Microsoft.TemplateEngine.Abstractions.IGenerator generator, Microsoft.TemplateEngine.Abstractions.Mount.IFile templateFile) Microsoft.TemplateEngine.Orchestrator.RunnableProjects.RunnableProjectGenerator.GetTemplatesFromMountPointInternalAsync(Microsoft.TemplateEngine.Abstractions.Mount.IMountPoint source, System.Threading.CancellationToken cancellationToken) Microsoft.TemplateEngine.Orchestrator.RunnableProjects.RunnableProjectGenerator.Microsoft.TemplateEngine.Abstractions.IGenerator.GetTemplatesFromMountPointAsync(Microsoft.TemplateEngine.Abstractions.Mount.IMountPoint source, System.Threading.CancellationToken cancellationToken) Microsoft.TemplateEngine.Edge.Settings.Scanner.ScanMountPointForTemplatesAsync(Microsoft.TemplateEngine.Edge.Settings.Scanner.MountPointScanSource source, bool logValidationResults, bool returnInvalidTemplates, System.Threading.CancellationToken cancellationToken) Microsoft.TemplateEngine.Edge.Settings.Scanner.ScanAsync(string mountPointUri, System.Threading.CancellationToken cancellationToken) Microsoft.TemplateEngine.Edge.Settings.TemplatePackageManager.UpdateTemplateCacheAsync.AnonymousMethod__2(int index) ```
joeloff
approved these changes
Aug 5, 2025
Member
joeloff
left a comment
There was a problem hiding this comment.
Is this something we should consider backporting for 8 and 9?
Member
Author
|
@joeloff I'm not sure. Seems low risk, but I don't know the impact. I'm not familiar with the merge policy for this repo. Please merge when makes sense. |
MiYanni
approved these changes
Aug 5, 2025
mmitche
pushed a commit
to dotnet/sdk
that referenced
this pull request
Apr 2, 2026
Commit migrated from dotnet/templating@5c71193
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FirstOrDefaultcan return null, so it's not safe to dereference unconditionally.Observed while debugging VS: