WinRT.Host misidentifies standard casing and probes outside its directory
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 665
- Forks
- 134
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 32
Description
Description
WinRT.Host.dll is the standard non-NativeAOT implementation name emitted by Microsoft.Windows.CsWinRT.Authoring.targets, but WinRT.Host.cpp recognizes its generic-host convention only when the host filename is exactly lowercase winrt.host.dll.
if (host_file.wstring() != L"winrt.host.dll")
On Windows, a normal WinRT.Host.dll is therefore treated as a renamed host. The renamed-host probing then repeatedly calls rfind('.') on the complete module path:
std::size_t count = target_path.rfind('.');
target_path.resize(count);
After exhausting the filename suffixes, this can consume a dot in a parent directory and probe outside the host directory.
Minimal reproduction
- Put the generic host and
WinRT.Host.runtimeconfig.jsonin a dotted directory, for exampleC:\build\Sample.Packaging\AppX\WinRT.Host.dll. - Put the actual authored assembly next to the host, for example
C:\build\Sample.Packaging\AppX\Contoso.Component.dll, and activateContoso.Component.Widget. - Place an unrelated
C:\build\Sample.dlladjacent toSample.Packaging. - Activate the runtime class.
Actual probe sequence includes:
C:\build\Sample.Packaging\AppX\WinRT.Host.Server.dll
C:\build\Sample.Packaging\AppX\WinRT.Server.dll
C:\build\Sample.Packaging\AppX\WinRT.dll
C:\build\Sample.Server.dll
C:\build\Sample.dll
The last candidate is outside the host directory. If it exists, the host loads it and class lookup can fail with CLASS_E_CLASSNOTAVAILABLE; otherwise class-name convention probing never reaches the expected Contoso.Component.dll.
Expected behavior
A generic host installed as the normal CsWinRT-authored WinRT.Host.dll should use class-name convention probing and resolve Contoso.Component.Widget to Contoso.Component.dll beside the host. Renamed-host probing must never traverse above the host directory.
Proposed fix
- Compare the generic-host filename case-insensitively.
- For renamed hosts, peel dot-separated suffixes from
host_module.filename()only, then combine each candidate filename with the original parent path.
Affected versions
The source file is identical in CsWinRT 2.3.1 and 3.0.0-preview.260319.2 (src/Authoring/WinRT.Host/WinRT.Host.cpp, blob 82566f5995536eb4d4432058db7ee2d57c2d5570), so the current 3.0 preview is also affected.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/Authoring/WinRT.Host/WinRT.Host.cpp and reproduce the issue using a dotted host directory and the filenames in the report. Check the generic-host filename comparison and the renamed-host probe candidates. Done means normal WinRT.Host.dll resolves the authored assembly beside it, while renamed-host probing does not leave the host directory.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- desktop, operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 75/100