Closed
Fix NullReferenceException when searching in Package Manager#17081
Conversation
…ty is null Root causes: 1. LuceneSearchUtility.InitializeLuceneConfig() dereferenced a null luceneUserDataFolder when the user data directory did not exist, causing LuceneSearchUtility constructor to fail and LuceneUtilityPackageManager to remain null. 2. PackageManagerSearchViewModel.Search() had no null guard for LuceneUtility. Fixes: 1. Remove unnecessary null-assignment; use userDataDir.FullName directly. 2. Add null guard in Search() that falls back to GetAllPackages() when LuceneUtility is null. 3. Add test verifying Search() handles null LuceneUtility without throwing. Agent-Logs-Url: https://github.com/DynamoDS/Dynamo/sessions/4541d380-1d27-4b81-9c54-469763ce1dfe Co-authored-by: zeusongit <32665108+zeusongit@users.noreply.github.com>
Agent-Logs-Url: https://github.com/DynamoDS/Dynamo/sessions/4541d380-1d27-4b81-9c54-469763ce1dfe Co-authored-by: zeusongit <32665108+zeusongit@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix unhandled exception in package manager search
Fix NullReferenceException when searching in Package Manager
Apr 28, 2026
|
| var userDataDir = new DirectoryInfo(dynamoModel.PathManager.UserDataDirectory); | ||
| luceneUserDataFolder = userDataDir.Exists ? userDataDir : null; | ||
| string indexPath = Path.Combine(luceneUserDataFolder.FullName, LuceneConfig.Index, startConfig.Directory); | ||
| string indexPath = Path.Combine(userDataDir.FullName, LuceneConfig.Index, startConfig.Directory); |
Contributor
|
@RobertGlobant20 I think this is a deeper problem with Civil3D as host related to the recent change, please take a look at the linked issue and PR analysis. |
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.



Typing in the Package Manager search box throws an unhandled
NullReferenceExceptionin certain host environments (e.g., Dynamo for Civil 3D) where the Lucene index fails to initialize, leavingLuceneSearch.LuceneUtilityPackageManagerasnull.Root causes
1. Null dereference in
LuceneSearchUtility.InitializeLuceneConfig()When
UserDataDirectorydoes not exist on disk,luceneUserDataFolderis set tonulland immediately dereferenced:This causes the
LuceneSearchUtilityconstructor to throw, soLuceneUtilityPackageManageris never assigned.2. No null guard in
PackageManagerSearchViewModel.Search()With
LuceneUtilitynull, accessingLuceneUtility.dirReaderthrows on every keystroke.Changes
LuceneSearchUtility.InitializeLuceneConfig()— UseuserDataDir.FullNamedirectly;FSDirectory.Opencreates the path as needed.PackageManagerSearchViewModel.Search()— Add null guard onLuceneUtility; fall back toGetAllPackages()if Lucene is unavailable.Search_WhenLuceneUtilityIsNull_ReturnsAllPackagesWithoutThrowing— Validates the null guard by forcingLuceneUtilityPackageManager = nullpost-construction and asserting no exception is thrown.