question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Analyzer reports unused constructor for MEF components.

See original GitHub issue

This 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:open
  • Created 3 years ago
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
mavasanicommented, Aug 21, 2020

Yes, I would be fine with modifying the analyzer here to ignore MEF import/export member symbols from analysis.

0reactions
sharwellcommented, Aug 23, 2020

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Suppress in source option for suppressing errors and ...
Suppressing analyzer diagnostics via suppress message attributes *is* supported. However, as attributes can only be applied to symbols, analyzer ...
Read more >
Attributed programming model overview (MEF)
Parameters declared as imports by the ImportingConstructor attribute are also marked as prerequisite imports. MEF normally allows exports and ...
Read more >
Untitled
The weeks band buttons, S'estol rei en jaume, 33340 ic, Yoshifan speedrun, Ghe o firefighter, Safran risotto thermomix, Joey logano race suit, Actrol...
Read more >
Managed Extensibility Framework - Building Composable ...
A programming model provides a means to declare components as MEF parts. ... When using an importing constructor, MEF assumes all parameters are...
Read more >
Full list of VisualGDB Settings
Full List of VisualGDB Settings · HardwareRegisters. Always Live Memory Engine · Keil. Expand all component groups · LiveVariables. Default Colors · MemoryExplorer....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found