Fix string overloads of EditorExtensionServiceProvider.GetService() on .NET#2332
Fix string overloads of EditorExtensionServiceProvider.GetService() on .NET#2332Copilot wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a platform-specific bug in the public extension API EditorExtensionServiceProvider.GetServiceByAssemblyQualifiedName(). On .NET (Core), the method resolved types via s_psesAsm.GetType(asmQualifiedTypeName), but Assembly.GetType() does not accept assembly-qualified names and returns null. As a result, all three string-based GetService() overloads (which funnel through this method) always failed on .NET Core, while the .NET Framework path worked because it already used Type.GetType().
The fix switches the .NET Core path to Type.GetType() (which accepts assembly-qualified names), still wrapped in EnterPsesAlcReflectionContext() so resolution honors the PSES assembly load context. This aligns both platform paths, and the contextual reflection scope ensures the type resolves from the correct ALC. The change only affects internal type-resolution behavior, so no public signatures change.
Changes:
- Replace
s_psesAsm.GetType(...)withType.GetType(...)on the .NET Core path inGetServiceByAssemblyQualifiedName. - Add
EditorExtensionServiceProviderTestscovering all three string-basedGetServiceoverloads against a registered service.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/PowerShellEditorServices/Extensions/Api/EditorExtensionServiceProvider.cs |
Fixes .NET Core type resolution to use Type.GetType, which accepts assembly-qualified names, within the PSES ALC reflection context. |
test/PowerShellEditorServices.Test/Extensions/EditorExtensionServiceProviderTests.cs |
New test class exercising the three GetService string overloads, following the existing ExtensionCommandTests setup pattern. |
On .NET (Core), all three string-based overloads of
EditorExtensionServiceProvider.GetService()always returned/failed becauseGetServiceByAssemblyQualifiedNameresolved types viaAssembly.GetType(asmQualifiedTypeName)— andAssembly.GetTypedoes not accept assembly-qualified names (it returnsnull). The .NET Framework path already usedType.GetType, which does, hence the platform discrepancy.Changes
EditorExtensionServiceProvider.GetServiceByAssemblyQualifiedName: on the .NET Core path, resolve viaType.GetType(asmQualifiedTypeName)instead ofs_psesAsm.GetType(...), still wrapped inEnterPsesAlcReflectionContext()so resolution honors the PSES assembly load context. Both platform paths now useType.GetType.EditorExtensionServiceProviderTestsexercising all three overloads against a registered service; they fail on the prior code and pass with the fix.Notes