Analyzer reports unused constructor for MEF components.
See original GitHub issueThis issue has been moved from a ticket on Developer Community.
Create a class with an Export
attribute and a private constructor with an ImportingConstructor
attribute on it. This denotes a MEF component that will invoke the private ctor instead of the default (parameterless) one. However, the VS code analyzer still “dims” the ctor and reports it as unused.
[Export(ExportContractNames.ProjectTreeProviders.PhysicalViewRootGraft, typeof(IProjectTreeProvider))]
internal class GlobalDesignerProjectTreeProvider : ProjectTreeProviderBase
{
[ImportingConstructor]
private GlobalDesignerProjectTreeProvider(
IProjectThreadingService threadingService,
UnconfiguredProject project)
: base(threadingService, project, configuredProjectExportsRequired: true)
{
}
Original Comments
Mila Zhou [MSFT] on 8/13/2020, 11:06 PM:
Could you please tell me what type of project you are? Web or others? Some screenshots will be better.
Feedback Bot on 8/17/2020, 02:55 AM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Feedback Bot on 8/17/2020, 09:33 AM:
Thank you for sharing your feedback! Our teams prioritize action on product issues with broad customer impact. See details at: https://docs.microsoft.com/en-us/visualstudio/ide/report-a-problem?view=vs-2019#faq. In case you need answers to common questions or need assisted support, be sure to use https://visualstudio.microsoft.com/vs/support/. We’ll keep you posted on any updates to this feedback.
Original Solutions
kirk solved on 8/14/2020, 06:48 AM, 0 votes:
It probably happens in any C# scenario, but the one above is a C# class library project targeting .NET 4.7.
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (10 by maintainers)
Yes, I would be fine with modifying the analyzer here to ignore MEF import/export member symbols from analysis.
@jmarolf there are a wide variety of reflection-based cases where that sentiment holds. Given the accessibility change has proven reliable as a design improvement to avoid this warning, I don’t see a lot of value in implementing this special case knowing there is no way we can cover so many others.