Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PT Run] Replace tblimp-Microsoft.Search.Interop package with source implementation #16363

Merged
merged 14 commits into from
Feb 16, 2022

Conversation

snickler
Copy link
Collaborator

@snickler snickler commented Feb 15, 2022

Summary of the Pull Request

image

What is this about:
This PR removes the tlbimp-Microsoft.Search.Interop NuGet package and replaces with COM Interop interfaces/classes to provide an implementation that works with what is currently used .

What is included in the PR:

  • tblimp-Microsoft.Search.Interop NuGet package removed
  • SearchAPI implementation of SearchManager, SearchQueryHelper, and SearchCatalogManager
  • Microsoft.Search.Interop.dll removed from Setup

How does someone test / validate:

  • Open Power Toys Run and enter a search term that should return results from files on your computer.
  • Place a breakpoint at the end of the ExecuteQuery method in WindowsSearchAPI.cs, Set thePowerLauncher project as the startup project and debug it. Verify the results list contains results from your local search index.

Quality Checklist

  • Linked issue: Remove all .NET Fx dependencies #8557
  • Communication: I've discussed this with core contributors in the issue.
  • Tests: Added/updated and all pass
  • Installer: Added/updated and all pass
  • Localization: All end user facing strings can be localized
  • Docs: Added/ updated
  • Binaries: Any new files are added to WXS / YML

Contributor License Agreement (CLA)

A CLA must be signed. If not, go over here and sign the CLA.

@crutkas
Copy link
Member

crutkas commented Feb 15, 2022

🔥🔥🔥

@Aaron-Junker Aaron-Junker added the Needs-Review This Pull Request awaits the review of a maintainer. label Feb 15, 2022
@jaimecbernardo
Copy link
Collaborator

Thanks a lot for opening this PR @snickler
This will really help in supporting arm64

Where do the class definitions come from, though? Any Microsoft docs or were they reverse engineered? Could you please link the source here or explain how you generated those?
Thanks, in advance.

@snickler
Copy link
Collaborator Author

Thanks a lot for opening this PR @snickler This will really help in supporting arm64

Where do the class definitions come from, though? Any Microsoft docs or were they reverse engineered? Could you please link the source here or explain how you generated those? Thanks, in advance.

It was generated using tlbimp.exe on SearchAPI.tlb per:

The tlb-Microsoft.Search.Interop NuGet package is the result of the command.

After generating the library, I initially used ILSpy and integrated the generated C# into the Indexer project, but I kept running into Access Violations when properties on the queryHelper were set. I went through tons of trial and error, used JetBrains dotPeek to generate the source properly.

I then realized what was wrong the entire time, it was because the definition for SearchAPI listed the put_xxxx methods before the set_xxxxx ones. ILSpy generates the C# source with { get; set } in that static order, whereas many properties needed to be { set; get }. It took me a while to realize it after using dotPeek.

When I verified it worked, I removed the bulk of the generated source files and kept only the minimal implementation of search based on ISearchManager, ISearchQueryHelper, ISearchCatalogManager use.

@jaimecbernardo
Copy link
Collaborator

Thanks a lot for the explanation @snickler !

Copy link
Collaborator

@jaimecbernardo jaimecbernardo left a comment

Choose a reason for hiding this comment

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

LGTM! The change works and seems like everything is in place.
Thanks a lot for the contribution!

@jaimecbernardo jaimecbernardo merged commit 35bfb0f into microsoft:main Feb 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Review This Pull Request awaits the review of a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants