找不到互操作类型'Microsoft.Internal.VisualStudio.Shell.Interop.SVsColorThemeService'

米哈伊尔·希什科夫(Mikhail Shishkov)

我正在使用Visual Studio 2013更新4社区版构建Visual Studio程序包/扩展。我正在使用可扩展性项目组下Visual Studio SDK随附的标准项目模板。在此处输入图片说明

我需要的是SVsColorThemeService但是当我在Initialize方法中添加以下行时

 var svc = GetGlobalService(typeof(SVsColorThemeService)) as IVsColorThemeService;

我收到两个构建错误:

Cannot find the interop type that matches the embedded interop type 'Microsoft.Internal.VisualStudio.Shell.Interop.SVsColorThemeService'. Are you missing an assembly reference?

Cannot find the interop type that matches the embedded interop type 'Microsoft.Internal.VisualStudio.Shell.Interop.IVsColorThemeService'. Are you missing an assembly reference?

在此处输入图片说明

所引用的程序集完全没有被触及。

所以寻找SVsColorThemeService反编译器就可以找到它

// Decompiled with JetBrains decompiler
// Type: Microsoft.Internal.VisualStudio.Shell.Interop.SVsColorThemeService
// Assembly: Microsoft.VisualStudio.Shell.12.0, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// MVID: B8FCA7E4-7D13-4E4B-A74B-6B6B01263DAF
// Assembly location: C:\Program Files (x86)\Microsoft Visual Studio 12.0\VSSDK\VisualStudioIntegration\Common\Assemblies\v4.0\Microsoft.VisualStudio.Shell.12.0.dll

using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace Microsoft.Internal.VisualStudio.Shell.Interop
{
  [CompilerGenerated]
  [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  [TypeIdentifier]
  [Guid("0D915B59-2ED7-472A-9DE8-9161737EA1C5")]
  [ComImport]
  public interface SVsColorThemeService
  {
  }
}

在此处输入图片说明

如您所见,程序集已被引用。因此,问题在于如何掌握SVsColorThemeServie并正确使用它?

EDIT1: After some research and following the @Simon Mourier suggestion I've added the following code to the solution:

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace Microsoft.Internal.VisualStudio.Shell.Interop
{
    [ComImport]
    [Guid("0D915B59-2ED7-472A-9DE8-9161737EA1C5")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface SVsColorThemeService
    {
    }

    [ComImport]
    [Guid("EAB552CF-7858-4F05-8435-62DB6DF60684")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IVsColorThemeService
    {
        IVsColorTheme CurrentTheme { get; }

        IVsColorThemes Themes { get; }

        void _VtblGap1_4();
        void _VtblGap2_1();
    }

    [ComImport]
    [Guid("98192AFE-75B9-4347-82EC-FF312C1995D8")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IVsColorThemes
    {
        IVsColorTheme GetThemeFromId([In] Guid ThemeId);
    }

    [ComImport]
    [Guid("413D8344-C0DB-4949-9DBC-69C12BADB6AC")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IVsColorTheme
    {
        Guid ThemeId { get; }

        void _VtblGap1_1();

        void Apply();
    }
}

What it does is to provide the missing interfaces for the COM objects. However it still won't build, throwing the same errors + warmings for conflicting types.

Warning 3   The type 'Microsoft.Internal.VisualStudio.Shell.Interop.IVsColorTheme' in 'c:\Users\Codemaster\Documents\Visual Studio 2013\Projects\VSPackage1\VSPackage1\Class1.cs' conflicts with the imported type 'Microsoft.Internal.VisualStudio.Shell.Interop.IVsColorTheme' in 'c:\Program Files (x86)\Microsoft Visual Studio 12.0\VSSDK\VisualStudioIntegration\Common\Assemblies\v4.0\Microsoft.VisualStudio.Shell.12.0.dll'. Using the type defined in 'c:\Users\Codemaster\Documents\Visual Studio 2013\Projects\VSPackage1\VSPackage1\Class1.cs'.    c:\users\codemaster\documents\visual studio 2013\Projects\VSPackage1\VSPackage1\Class1.cs   19  9   VSPackage1

Here is a Link where you can download the sample project: https://drive.google.com/file/d/0B7jBoLH-qaqTV09Mb1VCa3hld1E/view?usp=sharing

Simon Mourier

Some types in those VS assemblies require other assemblies (PIA). This is explained here: Troubleshooting Errors When Embedding Type Information (Doug Rothaus).

在这种特定于Visual Studio的情况下,除了手动重新创建类型之外,我不知道如何解决(那些程序集在哪里?)(提示:在这种情况下,请使用.NET反射器之类的工具来帮助您,因为DLL确实包含定义)。例如,以下是编译代码的方法,只需将其添加到某处:

namespace MyInterop
{
    [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("0D915B59-2ED7-472A-9DE8-9161737EA1C5")]
    public interface SVsColorThemeService
    {
    }
    [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("EAB552CF-7858-4F05-8435-62DB6DF60684")]
    public interface IVsColorThemeService {
        void _VtblGap1_4();
        IVsColorThemes Themes { [return: MarshalAs(UnmanagedType.Interface)] get; }
        IVsColorNames ColorNames { [return: MarshalAs(UnmanagedType.Interface)] get; }
        IVsColorTheme CurrentTheme { [return: MarshalAs(UnmanagedType.Interface)] get; }
    }
    [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("98192AFE-75B9-4347-82EC-FF312C1995D8")]
    public interface IVsColorThemes {
        [return: MarshalAs(UnmanagedType.Interface)]
        IVsColorTheme GetThemeFromId([In] Guid ThemeId);
    }
    [ComImport, Guid("413D8344-C0DB-4949-9DBC-69C12BADB6AC"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IVsColorTheme {
        void _VtblGap1_1();
        IVsColorEntry this[ColorName Name] { [return: MarshalAs(UnmanagedType.Interface)] get; }
        Guid ThemeId { get; }
    }
    [ComImport, TypeIdentifier, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("BBE70639-7AD9-4365-AE36-9877AF2F973B")]
    public interface IVsColorEntry {
        ColorName ColorName { get; }
        byte BackgroundType { get; }
        byte ForegroundType { get; }
        uint Background { get; }
        uint Foreground { get; }
    }
    public struct ColorName {
        public Guid Category;
        [MarshalAs(UnmanagedType.BStr)]
        public string Name;
    }
    [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("92144F7A-61DE-439B-AA66-13BE7CDEC857")]
    public interface IVsColorNames {
        void _VtblGap1_2();
        int Count { get; }
        System.Collections.IEnumerator GetEnumerator();
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

尽管在项目中未使用“ GAC缺少的Microsoft.VisualStudio.Shell.Interop.8.0版本8.0.0.0”,但ClickOnce部署失败?

.NET Core MSTest项目在Microsoft名称空间中找不到VisualStudio类型或名称空间

64位应用程序需要将Microsoft.VisualStudio.SourceSafe.Interop封装为32位进程

Microsoft Interop支持的文件

无法将类型为“ microsoft.Office.Interop.Excel.ApplicationClass”的COM对象转换为“ microsoft.Office.Interop.Excel.Application”

Visual Studio 2015无法加载包,因为Microsoft.VisualStudio.Shell.15.0无法加载

类型“ TestClassAttribute”同时存在于“ Microsoft.VisualStudio.QualityTools.UnitTestFramework”和“ Microsoft.VisualStudio.TestPlatform.TestFramework”中

类型'Microsoft.EntityFrameworkCore.Infrastructure.Internal.SqliteOptionsExtension'中的方法'Clone'

无法转换类型为'Microsoft.Office.Interop.Excel.WorksheetClass'的COM对象

无法将“System.String”类型的对象转换为“Microsoft.Office.Interop.Outlook.Store”

InvalidCastException-无法转换类型为“ Microsoft.Office.Interop.Outlook.ApplicationClass”的COM对象

无法从程序集“ Microsoft.EntityFrameworkCore”中加载类型“ Microsoft.EntityFrameworkCore.Internal.SemanticVersionComparer”,

Microsoft.Office.Interop.Word OMath

Office 2007的Microsoft.Office.Interop.Excel

Microsoft.Office.Interop.Excel的阅读范围

错误 VSSDK1001:无法找到 Microsoft.VisualStudio.CommandTable.VSCTCompiler 类型

无法将类型为“ System .__ ComObject”的COM对象转换为接口类型为“ Microsoft.Office.Interop.Excel.Worksheets”

C#-Microsoft.Office.Interop.Excel.Sheets到Microsoft.Office.Interop.Excel.Worksheet []

如何解决这个“无法将类型'对象'隐式转换为'Microsoft.Office.Interop.Excel.Worksheet'?

Microsoft.VisualStudio.Profiler.dll在哪里?

VS 2012中的Microsoft.VisualStudio.Package

从Mono使用Microsoft.VisualStudio.Web.targets?

Microsoft.VisualStudio.TestTools.UITesting,版本= 14.0.0.0

如何使用Microsoft.VisualStudio.Web.CodeGeneration?

无法从程序集Microsoft.AspNetCore.Routing Ver = 3.1.7.0中加载类型Microsoft.AspNetCore.Internal.EndpointRoutingApplicationBuilderExtensions

IFormFile无法从程序集'Microsoft.AspNetCore.Http 3.0'中加载类型Microsoft.AspNetCore.Http.Internal.FormFile'

Microsoft.VisualStudio.TestPlatform.TestFramework和Microsoft.VisualStudio.QualityTools.UnitTestFramework之间的区别

传递到 ViewDataDictionary 的模型项的类型为“Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable

找不到Shell命令