- Notifications
You must be signed in to change notification settings - Fork394
Fix NullReferenceException#9225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
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 left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Is this something we should consider backporting for 8 and 9?
drewnoakes commentedAug 5, 2025
@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. |
5c71193 intomainUh oh!
There was an error while loading.Please reload this page.
FirstOrDefaultcan return null, so it's not safe to dereference unconditionally.Observed while debugging VS: