SpecFlow:打开功能文件导致 NullReferenceException

SpecFlow: Opening a feature file result in a NullReferenceException

几个星期以来,我突然遇到 Visual Studio 2019(专业版)中的 SpecFlow 扩展问题。它突然停止工作。首先我认为是因为 VS 的更新,但我的其他同事正在使用相同(最新)版本的 VS,并且 SpecFlow 对他们有效。

我遇到的问题是:

测试资源管理器仍在发现测试,我仍然可以 运行 它们,但不是来自功能文件(既不调试步骤)。

扩展已正确安装和启用(据我所知)。 已尝试以下但未成功:

你们中有人知道是什么原因造成的吗?

Activity 日志条目

<entry>
  <record>806</record>
  <time>2021/02/09 09:25:56.786</time>
  <type>Error</type>
  <source>Editor or Editor Extension</source>
  <description>System.NullReferenceException: Object reference not set to an instance of an object.&#x000D;&#x000A;
    at TechTalk.SpecFlow.VsIntegration.LanguageService.ProjectScopeFactory.&lt;.ctor&gt;b__9_0() in D:\a\s\TechTalk.SpecFlow.VSIXShared\LanguageService\ProjectScopeFactory.cs:line 52&#x000D;&#x000A;
    at TechTalk.SpecFlow.VsIntegration.Implementation.Utils.SynchInitializedInstance`1.EnsureInitialized()&#x000D;&#x000A;
    at TechTalk.SpecFlow.VsIntegration.LanguageService.ProjectScopeFactory.&lt;.ctor&gt;b__9_2(Project project) in D:\a\s\TechTalk.SpecFlow.VSIXShared\LanguageService\ProjectScopeFactory.cs:line 64&#x000D;&#x000A;
    at TechTalk.SpecFlow.VsIntegration.Implementation.Utils.SynchronizedResultCache`3.GetOrCreate(TSource source)&#x000D;&#x000A;
    at TechTalk.SpecFlow.VsIntegration.LanguageService.ProjectScopeFactory.GetProjectScope(Project project) in D:\a\s\TechTalk.SpecFlow.VSIXShared\LanguageService\ProjectScopeFactory.cs:line 76&#x000D;&#x000A;
    at TechTalk.SpecFlow.VsIntegration.LanguageService.GherkinLanguageServiceFactory.CreateLanguageService(ITextBuffer textBuffer) in D:\a\s\TechTalk.SpecFlow.VSIXShared\LanguageService\GherkinLanguageServiceFactory.cs:line 51&#x000D;&#x000A;
    at TechTalk.SpecFlow.VsIntegration.LanguageService.GherkinLanguageServiceFactory.&lt;&gt;c__DisplayClass7_0.&lt;GetLanguageService&gt;b__0() in D:\a\s\TechTalk.SpecFlow.VSIXShared\LanguageService\GherkinLanguageServiceFactory.cs:line 43&#x000D;&#x000A;
    at TechTalk.SpecFlow.VsIntegration.LanguageService.GherkinBufferServiceManager.&lt;&gt;c__DisplayClass3_0`1.&lt;GetOrCreate&gt;b__0() in D:\a\s\TechTalk.SpecFlow.VSIXShared\LanguageService\GherkinBufferServiceManager.cs:line 32&#x000D;&#x000A;
    at Microsoft.VisualStudio.Utilities.PropertyCollection.GetOrCreateSingletonProperty[T](Object key, Func`1 creator)&#x000D;&#x000A;
    at TechTalk.SpecFlow.VsIntegration.LanguageService.GherkinBufferServiceManager.GetOrCreate[TService](ITextBuffer textBuffer, Func`1 creator) in D:\a\s\TechTalk.SpecFlow.VSIXShared\LanguageService\GherkinBufferServiceManager.cs:line 29&#x000D;&#x000A;
    at TechTalk.SpecFlow.VsIntegration.LanguageService.GherkinLanguageServiceFactory.GetLanguageService(ITextBuffer textBuffer) in D:\a\s\TechTalk.SpecFlow.VSIXShared\LanguageService\GherkinLanguageServiceFactory.cs:line 43&#x000D;&#x000A;
    at TechTalk.SpecFlow.VsIntegration.GherkinFileEditor.GherkinFileClassifierProvider.&lt;&gt;c__DisplayClass3_0.&lt;GetClassifier&gt;b__0() in D:\a\s\TechTalk.SpecFlow.VSIXShared\GherkinFileEditor\GherkinFileClassifierProvider.cs:line 31&#x000D;&#x000A;
    at TechTalk.SpecFlow.VsIntegration.LanguageService.GherkinBufferServiceManager.&lt;&gt;c__DisplayClass3_0`1.&lt;GetOrCreate&gt;b__0() in D:\a\s\TechTalk.SpecFlow.VSIXShared\LanguageService\GherkinBufferServiceManager.cs:line 32&#x000D;&#x000A;
    at Microsoft.VisualStudio.Utilities.PropertyCollection.GetOrCreateSingletonProperty[T](Object key, Func`1 creator)&#x000D;&#x000A;
    at TechTalk.SpecFlow.VsIntegration.LanguageService.GherkinBufferServiceManager.GetOrCreate[TService](ITextBuffer textBuffer, Func`1 creator) in D:\a\s\TechTalk.SpecFlow.VSIXShared\LanguageService\GherkinBufferServiceManager.cs:line 29&#x000D;&#x000A;
    at TechTalk.SpecFlow.VsIntegration.GherkinFileEditor.GherkinFileClassifierProvider.GetClassifier(ITextBuffer buffer) in D:\a\s\TechTalk.SpecFlow.VSIXShared\GherkinFileEditor\GherkinFileClassifierProvider.cs:line 30&#x000D;&#x000A;
    at Microsoft.VisualStudio.Text.Classification.Implementation.ClassifierTaggerProvider.&lt;&gt;c__DisplayClass12_0`1.&lt;CreateTagger&gt;b__0(IClassifierProvider provider)&#x000D;&#x000A;
    at Microsoft.VisualStudio.Text.Utilities.GuardedOperations.InvokeEligibleFactories[TExtensionInstance,TExtensionFactory,TMetadataView](IEnumerable`1 lazyFactories, Func`2 getter, IContentType dataContentType, IContentTypeRegistryService contentTypeRegistryService, Object errorSource)&#x000D;&#x000A;--- End of stack trace from previous location where exception was thrown ---&#x000D;&#x000A;
    at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)
  </description>
</entry>

已编辑: 运行修复 VS 后,我可以看到 'Clear MEF Component Cache' 扩展的菜单选项。不幸的是,使用它让我无法进一步使用 SpecFlow 扩展(仍然是相同的问题)。

这看起来 Visual Studio 的 MEF 缓存有问题。
清理它的一种简单方法是 Mads Kristensen 的 Clear MEF Component Cache 扩展。它可以在此处的市场上找到:https://marketplace.visualstudio.com/items?itemName=MadsKristensen.ClearMEFComponentCache

安装并重启VS后,执行菜单中的命令:

之后,再次重启 VS,SpecFlow VS Extension 应该会再次运行。

由于不同的问题,我从 IT 部门收到了我笔记本电脑上的全新图像。因此,SpecFlow 的问题也已解决。我仍然不知道到底是什么原因造成的,但我猜可能是由于注册表轻微损坏或类似原因造成的。

反正不用再回答了