SpecFlow:打开功能文件导致 NullReferenceException
SpecFlow: Opening a feature file result in a NullReferenceException
几个星期以来,我突然遇到 Visual Studio 2019(专业版)中的 SpecFlow 扩展问题。它突然停止工作。首先我认为是因为 VS 的更新,但我的其他同事正在使用相同(最新)版本的 VS,并且 SpecFlow 对他们有效。
我遇到的问题是:
- 没有 SpecFlow 的设置菜单(工具 - 选项 - SpecFlow)
- 打开功能文件时出现 NullReferenceException(请参阅 post 的末尾以获取 activity 日志的条目)
- 打开功能文件时没有语法高亮显示
- 没有上下文菜单
测试资源管理器仍在发现测试,我仍然可以 运行 它们,但不是来自功能文件(既不调试步骤)。
扩展已正确安装和启用(据我所知)。
已尝试以下但未成功:
- 为 Visual Studio 2019 扩展卸载并安装 SpecFlow
- 卸载 SpecFlow 并安装 Deveroom
- 卸载Visual Studio 2019 并重新安装
你们中有人知道是什么原因造成的吗?
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.

at TechTalk.SpecFlow.VsIntegration.LanguageService.ProjectScopeFactory.<.ctor>b__9_0() in D:\a\s\TechTalk.SpecFlow.VSIXShared\LanguageService\ProjectScopeFactory.cs:line 52

at TechTalk.SpecFlow.VsIntegration.Implementation.Utils.SynchInitializedInstance`1.EnsureInitialized()

at TechTalk.SpecFlow.VsIntegration.LanguageService.ProjectScopeFactory.<.ctor>b__9_2(Project project) in D:\a\s\TechTalk.SpecFlow.VSIXShared\LanguageService\ProjectScopeFactory.cs:line 64

at TechTalk.SpecFlow.VsIntegration.Implementation.Utils.SynchronizedResultCache`3.GetOrCreate(TSource source)

at TechTalk.SpecFlow.VsIntegration.LanguageService.ProjectScopeFactory.GetProjectScope(Project project) in D:\a\s\TechTalk.SpecFlow.VSIXShared\LanguageService\ProjectScopeFactory.cs:line 76

at TechTalk.SpecFlow.VsIntegration.LanguageService.GherkinLanguageServiceFactory.CreateLanguageService(ITextBuffer textBuffer) in D:\a\s\TechTalk.SpecFlow.VSIXShared\LanguageService\GherkinLanguageServiceFactory.cs:line 51

at TechTalk.SpecFlow.VsIntegration.LanguageService.GherkinLanguageServiceFactory.<>c__DisplayClass7_0.<GetLanguageService>b__0() in D:\a\s\TechTalk.SpecFlow.VSIXShared\LanguageService\GherkinLanguageServiceFactory.cs:line 43

at TechTalk.SpecFlow.VsIntegration.LanguageService.GherkinBufferServiceManager.<>c__DisplayClass3_0`1.<GetOrCreate>b__0() in D:\a\s\TechTalk.SpecFlow.VSIXShared\LanguageService\GherkinBufferServiceManager.cs:line 32

at Microsoft.VisualStudio.Utilities.PropertyCollection.GetOrCreateSingletonProperty[T](Object key, Func`1 creator)

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

at TechTalk.SpecFlow.VsIntegration.LanguageService.GherkinLanguageServiceFactory.GetLanguageService(ITextBuffer textBuffer) in D:\a\s\TechTalk.SpecFlow.VSIXShared\LanguageService\GherkinLanguageServiceFactory.cs:line 43

at TechTalk.SpecFlow.VsIntegration.GherkinFileEditor.GherkinFileClassifierProvider.<>c__DisplayClass3_0.<GetClassifier>b__0() in D:\a\s\TechTalk.SpecFlow.VSIXShared\GherkinFileEditor\GherkinFileClassifierProvider.cs:line 31

at TechTalk.SpecFlow.VsIntegration.LanguageService.GherkinBufferServiceManager.<>c__DisplayClass3_0`1.<GetOrCreate>b__0() in D:\a\s\TechTalk.SpecFlow.VSIXShared\LanguageService\GherkinBufferServiceManager.cs:line 32

at Microsoft.VisualStudio.Utilities.PropertyCollection.GetOrCreateSingletonProperty[T](Object key, Func`1 creator)

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

at TechTalk.SpecFlow.VsIntegration.GherkinFileEditor.GherkinFileClassifierProvider.GetClassifier(ITextBuffer buffer) in D:\a\s\TechTalk.SpecFlow.VSIXShared\GherkinFileEditor\GherkinFileClassifierProvider.cs:line 30

at Microsoft.VisualStudio.Text.Classification.Implementation.ClassifierTaggerProvider.<>c__DisplayClass12_0`1.<CreateTagger>b__0(IClassifierProvider provider)

at Microsoft.VisualStudio.Text.Utilities.GuardedOperations.InvokeEligibleFactories[TExtensionInstance,TExtensionFactory,TMetadataView](IEnumerable`1 lazyFactories, Func`2 getter, IContentType dataContentType, IContentTypeRegistryService contentTypeRegistryService, Object errorSource)
--- End of stack trace from previous location where exception was thrown ---

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 的问题也已解决。我仍然不知道到底是什么原因造成的,但我猜可能是由于注册表轻微损坏或类似原因造成的。
反正不用再回答了
几个星期以来,我突然遇到 Visual Studio 2019(专业版)中的 SpecFlow 扩展问题。它突然停止工作。首先我认为是因为 VS 的更新,但我的其他同事正在使用相同(最新)版本的 VS,并且 SpecFlow 对他们有效。
我遇到的问题是:
- 没有 SpecFlow 的设置菜单(工具 - 选项 - SpecFlow)
- 打开功能文件时出现 NullReferenceException(请参阅 post 的末尾以获取 activity 日志的条目)
- 打开功能文件时没有语法高亮显示
- 没有上下文菜单
测试资源管理器仍在发现测试,我仍然可以 运行 它们,但不是来自功能文件(既不调试步骤)。
扩展已正确安装和启用(据我所知)。 已尝试以下但未成功:
- 为 Visual Studio 2019 扩展卸载并安装 SpecFlow
- 卸载 SpecFlow 并安装 Deveroom
- 卸载Visual Studio 2019 并重新安装
你们中有人知道是什么原因造成的吗?
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.

at TechTalk.SpecFlow.VsIntegration.LanguageService.ProjectScopeFactory.<.ctor>b__9_0() in D:\a\s\TechTalk.SpecFlow.VSIXShared\LanguageService\ProjectScopeFactory.cs:line 52

at TechTalk.SpecFlow.VsIntegration.Implementation.Utils.SynchInitializedInstance`1.EnsureInitialized()

at TechTalk.SpecFlow.VsIntegration.LanguageService.ProjectScopeFactory.<.ctor>b__9_2(Project project) in D:\a\s\TechTalk.SpecFlow.VSIXShared\LanguageService\ProjectScopeFactory.cs:line 64

at TechTalk.SpecFlow.VsIntegration.Implementation.Utils.SynchronizedResultCache`3.GetOrCreate(TSource source)

at TechTalk.SpecFlow.VsIntegration.LanguageService.ProjectScopeFactory.GetProjectScope(Project project) in D:\a\s\TechTalk.SpecFlow.VSIXShared\LanguageService\ProjectScopeFactory.cs:line 76

at TechTalk.SpecFlow.VsIntegration.LanguageService.GherkinLanguageServiceFactory.CreateLanguageService(ITextBuffer textBuffer) in D:\a\s\TechTalk.SpecFlow.VSIXShared\LanguageService\GherkinLanguageServiceFactory.cs:line 51

at TechTalk.SpecFlow.VsIntegration.LanguageService.GherkinLanguageServiceFactory.<>c__DisplayClass7_0.<GetLanguageService>b__0() in D:\a\s\TechTalk.SpecFlow.VSIXShared\LanguageService\GherkinLanguageServiceFactory.cs:line 43

at TechTalk.SpecFlow.VsIntegration.LanguageService.GherkinBufferServiceManager.<>c__DisplayClass3_0`1.<GetOrCreate>b__0() in D:\a\s\TechTalk.SpecFlow.VSIXShared\LanguageService\GherkinBufferServiceManager.cs:line 32

at Microsoft.VisualStudio.Utilities.PropertyCollection.GetOrCreateSingletonProperty[T](Object key, Func`1 creator)

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

at TechTalk.SpecFlow.VsIntegration.LanguageService.GherkinLanguageServiceFactory.GetLanguageService(ITextBuffer textBuffer) in D:\a\s\TechTalk.SpecFlow.VSIXShared\LanguageService\GherkinLanguageServiceFactory.cs:line 43

at TechTalk.SpecFlow.VsIntegration.GherkinFileEditor.GherkinFileClassifierProvider.<>c__DisplayClass3_0.<GetClassifier>b__0() in D:\a\s\TechTalk.SpecFlow.VSIXShared\GherkinFileEditor\GherkinFileClassifierProvider.cs:line 31

at TechTalk.SpecFlow.VsIntegration.LanguageService.GherkinBufferServiceManager.<>c__DisplayClass3_0`1.<GetOrCreate>b__0() in D:\a\s\TechTalk.SpecFlow.VSIXShared\LanguageService\GherkinBufferServiceManager.cs:line 32

at Microsoft.VisualStudio.Utilities.PropertyCollection.GetOrCreateSingletonProperty[T](Object key, Func`1 creator)

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

at TechTalk.SpecFlow.VsIntegration.GherkinFileEditor.GherkinFileClassifierProvider.GetClassifier(ITextBuffer buffer) in D:\a\s\TechTalk.SpecFlow.VSIXShared\GherkinFileEditor\GherkinFileClassifierProvider.cs:line 30

at Microsoft.VisualStudio.Text.Classification.Implementation.ClassifierTaggerProvider.<>c__DisplayClass12_0`1.<CreateTagger>b__0(IClassifierProvider provider)

at Microsoft.VisualStudio.Text.Utilities.GuardedOperations.InvokeEligibleFactories[TExtensionInstance,TExtensionFactory,TMetadataView](IEnumerable`1 lazyFactories, Func`2 getter, IContentType dataContentType, IContentTypeRegistryService contentTypeRegistryService, Object errorSource)
--- End of stack trace from previous location where exception was thrown ---

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 的问题也已解决。我仍然不知道到底是什么原因造成的,但我猜可能是由于注册表轻微损坏或类似原因造成的。
反正不用再回答了