Exception during initialization of a CodeRefactoringProvider when trying to import DTE

自古美人都是妖i 提交于 2020-01-25 10:10:09

问题


I am building a custom code refactoring provider as an extension to Visual Studio 2017 and I want it to access the DTE service. To get it I use the ImportingConstructorAttribute and declare the service a parameter:

[ExportCodeRefactoringProvider( LanguageNames.CSharp, Name = nameof( MyCodeRefactoringProvider ) )]
[Shared]
internal class MyCodeRefactoringProvider : CodeRefactoringProvider {
    private readonly DTE m_dte;

    [ImportingConstructor]
    public MyCodeRefactoringProvider( DTE dte ) {
        m_dte = dte;
    }

    public sealed override async Task ComputeRefactoringsAsync( CodeRefactoringContext context ) {
        //...
    }
}

However, when I run the provider in the Visual Studio experimental instance, the provider is not instantiated.

The refactoring provider works fine if I don't try to import the service provider. The same issue occurs if I use the ImportAttribute on a property instead of the ImportingConstructorAttribute.

There was also nothing in the ActivityLog.xml of Visual Studio.

How can I import DTE through MEF?

来源:https://stackoverflow.com/questions/53860813/exception-during-initialization-of-a-coderefactoringprovider-when-trying-to-impo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!