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

Test composition fails when a part is rejected #60690

Open
tmat opened this issue Apr 11, 2022 · 3 comments
Open

Test composition fails when a part is rejected #60690

tmat opened this issue Apr 11, 2022 · 3 comments
Assignees
Labels
Milestone

Comments

@tmat
Copy link
Member

tmat commented Apr 11, 2022

PR #60687 added a new TypeScipt External Access language service, which imports implementation interface that's not implemented in the composition. The test composition should just ignore this service.

System.Composition.Hosting.CompositionFailedException : No export was found for the contract 'IVSTypeScriptCommentSelectionServiceImplementation'
-> required by import 'impl' of part 'VSTypeScriptCommentSelectionService'
-> required by import 'value' of part 'Lazy<ILanguageService, LanguageServiceMetadata>'
-> required by import 'item' of part 'Lazy`2[]'
-> required by initial request for contract 'IEnumerable<Lazy<ILanguageService, LanguageServiceMetadata>> { IsImportMany = True }'

Stack trace

...
Microsoft.CodeAnalysis.Host.CodeStyleHostLanguageServices.MefHostExportProvider.Microsoft.CodeAnalysis.Host.Mef.IMefHostExportProvider.GetExports[TExtension,TMetadata]() in /_/src/CodeStyle/Core/CodeFixes/Host/Mef/CodeStyleHostLanguageServices.cs.cs:line 61
   at Microsoft.CodeAnalysis.Host.Mef.MefLanguageServices..ctor(MefWorkspaceServices workspaceServices, String language) in /_/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Workspace/Mef/MefLanguageServices.cs:line 37
   at Microsoft.CodeAnalysis.Host.Mef.MefWorkspaceServices.<>c.<GetLanguageServices>b__21_0(String languageName, MefWorkspaceServices self) in /_/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Workspace/Mef/MefWorkspaceServices.cs:line 163
   at System.Collections.Immutable.ImmutableInterlocked.GetOrAdd[TKey,TValue,TArg](ImmutableDictionary`2& location, TKey key, Func`3 valueFactory, TArg factoryArgument)
   at Microsoft.CodeAnalysis.Host.Mef.MefWorkspaceServices.GetLanguageServices(String languageName) in /_/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Workspace/Mef/MefWorkspaceServices.cs:line 163
   at Microsoft.CodeAnalysis.Host.CodeStyleHostLanguageServices..ctor(HostLanguageServices hostLanguageServices) in /_/src/CodeStyle/Core/CodeFixes/Host/Mef/CodeStyleHostLanguageServices.MefHostExportProvider.cs:line 27
   at Microsoft.CodeAnalysis.Host.CodeStyleHostLanguageServices.Create(HostLanguageServices hostLanguageServices) in /_/src/CodeStyle/Core/CodeFixes/Host/Mef/CodeStyleHostLanguageServices.MefHostExportProvider.cs:line 38
   at System.Runtime.CompilerServices.ConditionalWeakTable`2.GetValue(TKey key, CreateValueCallback createValueCallback)
   at Microsoft.CodeAnalysis.Host.CodeStyleHostLanguageServices.GetRequiredMappedCodeStyleLanguageServices(HostLanguageServices hostLanguageServices) in /_/src/CodeStyle/Core/CodeFixes/Host/Mef/CodeStyleHostLanguageServices.MefHostExportProvider.cs:line 35
   at Microsoft.CodeAnalysis.Host.HostWorkspaceServicesExtensions.GetExtendedLanguageServices(HostWorkspaceServices hostWorkspaceServices, String languageName) in 
...
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 11, 2022
@tmat tmat added the Test Test failures in roslyn-CI label Apr 11, 2022
@jinujoseph jinujoseph added Investigation Required and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 19, 2022
@jinujoseph jinujoseph added this to the 17.3 milestone Apr 19, 2022
@sharwell
Copy link
Member

@tmat MEF 2 does not support silent part rejection. Parts defined in the Workspaces or Features layer (where VS MEF might not be used) that need to silently exclude themselves must follow this pattern:
#59047

@sharwell
Copy link
Member

Specifically, you want this pattern:

internal readonly IVSTypeScriptDiagnosticAnalyzerImplementation Implementation;
// 'implementation' is a required import, but MEF 2 does not support silent part rejection when a required
// import is missing so we combine AllowDefault with a null check in the constructor to defer the exception
// until the part is instantiated.
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public VSTypeScriptDiagnosticAnalyzerLanguageService(
[Import(AllowDefault = true)] IVSTypeScriptDiagnosticAnalyzerImplementation? implementation)
{
Implementation = implementation ?? throw new ArgumentNullException(nameof(implementation));
}

@arunchndr arunchndr modified the milestones: 17.3, 17.6 P2 Jan 17, 2023
@arunchndr arunchndr modified the milestones: 17.6 P2, Backlog Oct 29, 2024
@CyrusNajmabadi CyrusNajmabadi modified the milestones: Backlog, 17.13 Nov 21, 2024
@CyrusNajmabadi
Copy link
Member

@sharwell moved to 17.13. Close out if you do not think we will do anything here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants