【问题标题】:Roslyn in a VSIX project: Unable to cast object of type ComponentModel to IComponentModelVSIX 项目中的 Roslyn:无法将 ComponentModel 类型的对象转换为 IComponentModel
【发布时间】:2017-02-28 16:54:34
【问题描述】:

我一直在 VSIX 项目中试用 Roslyn。目前我想做的是加载 CurrentSolution。但是我最终得到了错误:

Unable to cast object of type 'Microsoft.VisualStudio.ComponentModelHost.ComponentModel' 
to type 'Microsoft.VisualStudio.ComponentModelHost.IComponentModel'.

我已经为 Microsoft.VisualStudio.LanguageServices 和 Microsoft.VisualStudio.ComponentModelHost 安装了 NuGet 包。

在我的 VSIX 命令包类的 Initialize 方法中,我添加了这个:

var componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));
var workspace = (Workspace)componentModel.GetService<VisualStudioWorkspace>();

这给了我我提到的例外。

Microsoft.VisualStudio.ComponentModelHost DLL 的版本是 15.0.0.0。

已经试过了:

  • 删除 BIN 文件夹并重建

  • 重新启动 Visual Studio

我只是不确定是什么原因造成的,而且似乎无法找到有关此错误的信息,我们将不胜感激。

【问题讨论】:

  • 得到了检查 GAC 以获取此 DLL 版本的想法。原来我有两个。通过 Nuget 包管理器,我安装了 DLL 的 15.0.0.0 版本。但我已经有一个 14.0.0.0 版本(不确定它来自哪里)。我从 GAC 和我的项目的引用中删除了 15.0.0.0,然后添加了现有的 14.0.0.0 引用。现在投射没有问题。
  • 您可以发布您自己问题的答案并接受它以供将来找到它的人使用。
  • 花了我一段时间,但完成了 ;-)

标签: c# visual-studio-2015 roslyn vsix


【解决方案1】:

想到了在 GAC 中检查此 DLL 的版本。原来我有两个。通过 Nuget 包管理器,我安装了 DLL 的 15.0.0.0 版本。但我已经有一个 14.0.0.0 版本(不确定它来自哪里)。我从 GAC 和我的项目的引用中删除了 15.0.0.0,然后添加了现有的 14.0.0.0 引用。现在投射没有问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-05
    • 1970-01-01
    • 1970-01-01
    • 2021-12-06
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多