locked
How To Register VCCodeModel Interface? RRS feed

  • Question

  • I have installed the VS Extensibility workload in VS 2017 Pro. However, at least one of the interfaces fails to instantiate with the following error:

    'Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.VisualStudio.VCCodeModel.VCCodeModel'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{A590E96B-CC8C-48AF-9E8F-7C3FE7865586}' failed due to the following error: Interface not registered (Exception from HRESULT: 0x80040155).'

    I assumed that all the code model interfaces would be registered when I installed the extensibility workload.

    What do you think has gone wrong?

    I am following the example given on this page:

    https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.vccodemodel.vccodemodel(v=vs.140).aspx

    • Moved by 宝宝徐 Tuesday, August 29, 2017 3:00 AM
    Monday, August 28, 2017 11:33 PM

Answers

  • Hi Richard,

    According to the example you provided, I tested in my Visual Studio 2017, it works fine. Following is my sample code which I have convert it to C# code. Please check whether there has any difference. If possible, you could share your code here to let us check whether there has any problem in your code.

            string message;
            public VCCodeModel GetVCCodeModel()
            {
                CodeModel codeModel;
                VCCodeModel vcCodeModel = null;
                Solution solution;
    
                var dte = (EnvDTE.DTE)this.ServiceProvider.GetService(typeof(EnvDTE.DTE));
                if (dte != null)
                {
                    solution = dte.Solution;
                    if (solution.Count != 0)
                    {
                        codeModel = dte.Solution.Item(1).CodeModel;
                        vcCodeModel = (VCCodeModel)codeModel;
    
                        if (vcCodeModel == null)
                        {
                            message = ("The first project is not a VC++ project.");
                        }
                    }
                    else
                    {
                        message = "A Solution is not open";
                    }
                }
    
                return vcCodeModel;
    
            }
    
    

    And based on the error message, there has any register problem in your 'Microsoft.VisualStudio.VCCodeModel’ when installing your Visual Studio 2017. Please try with following steps to repair Visual Studio 2017.

    1. To make sure whether it is related to corrupted .net frameworks, please take the following steps      to see if it helps:
        1. Register the  Microsoft.VisualStudio.VCCodeModel component with Regasm.exe. Open Developer Command Prompt for Visual Studio 2017 as Administrator and type following command: regasm "The path of the assembly that you want to register\Microsoft.VisualStudio.VCCodeModel.dll"
    • Repair your Visual Studio 2017

      Best Regards,
      Weiwei


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Weiwei Cai Friday, September 1, 2017 5:09 AM
    • Marked as answer by Richard x64 Friday, September 1, 2017 7:16 PM
    Tuesday, August 29, 2017 6:16 AM

All replies

  • Hi Richard,

    Thank you for posting in MSDN forum.

    This forum is about VS setup and installation, from your description, this issue is much related to VSX, I help you move this case to VSX forum to get a better professional support.

    Thank you for your understanding and cooperation.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, August 29, 2017 3:00 AM
  • Hi Richard,

    According to the example you provided, I tested in my Visual Studio 2017, it works fine. Following is my sample code which I have convert it to C# code. Please check whether there has any difference. If possible, you could share your code here to let us check whether there has any problem in your code.

            string message;
            public VCCodeModel GetVCCodeModel()
            {
                CodeModel codeModel;
                VCCodeModel vcCodeModel = null;
                Solution solution;
    
                var dte = (EnvDTE.DTE)this.ServiceProvider.GetService(typeof(EnvDTE.DTE));
                if (dte != null)
                {
                    solution = dte.Solution;
                    if (solution.Count != 0)
                    {
                        codeModel = dte.Solution.Item(1).CodeModel;
                        vcCodeModel = (VCCodeModel)codeModel;
    
                        if (vcCodeModel == null)
                        {
                            message = ("The first project is not a VC++ project.");
                        }
                    }
                    else
                    {
                        message = "A Solution is not open";
                    }
                }
    
                return vcCodeModel;
    
            }
    
    

    And based on the error message, there has any register problem in your 'Microsoft.VisualStudio.VCCodeModel’ when installing your Visual Studio 2017. Please try with following steps to repair Visual Studio 2017.

    1. To make sure whether it is related to corrupted .net frameworks, please take the following steps      to see if it helps:
        1. Register the  Microsoft.VisualStudio.VCCodeModel component with Regasm.exe. Open Developer Command Prompt for Visual Studio 2017 as Administrator and type following command: regasm "The path of the assembly that you want to register\Microsoft.VisualStudio.VCCodeModel.dll"
    • Repair your Visual Studio 2017

      Best Regards,
      Weiwei


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Weiwei Cai Friday, September 1, 2017 5:09 AM
    • Marked as answer by Richard x64 Friday, September 1, 2017 7:16 PM
    Tuesday, August 29, 2017 6:16 AM
  • Please advice why you would discontinue my investigation??
                

    P7 - 0x80048646 When installing Android SDK (API level 19 - 23)

    What am I suppose to do now as I cant post there anymore

    Tuesday, August 29, 2017 7:29 AM
  • Thank you Weiwei.

    I tried your code, but I don't know what object is represented by "this" in the following line:

     var dte = (EnvDTE.DTE)this.ServiceProvider.GetService(typeof(EnvDTE.DTE));

    What object is "this"?

    It cannot resolve the reference to ServiceProvider.

    This is the code I am using in my program.

            private void buttonExtract_Click(object sender, EventArgs e)
            {
                EnvDTE80.DTE2 dte2 =
                    (DTE2) System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.15.0");
    
                int Count = dte2.Solution.Projects.Count;
                Project P = null;
    
                for (int a = 1; a <= Count; a++)
                {
                    P = dte2.Solution.Projects.Item(a);
    
                    if (P.FullName.Contains("ConsoleApplication"))
                    {
                        break;
                    }
                }
    
                VCCodeModel vcCodeModel = (VCCodeModel) P.CodeModel; // <<<<< BOMBS HERE
            }
    

    • Edited by Richard x64 Tuesday, August 29, 2017 10:30 PM
    Tuesday, August 29, 2017 10:17 PM
  • Hi Richard x64,

    The "this" keyword point to the Command class which used to implement the command function. I create a VSIX project and add a custom command to write the VCCodeModel. In Command.cs file, it has a ServiceProvider property.

    Following is my sample project. You could download it to check how does it working.

    https://1drv.ms/u/s!AkHKK8SV6besg3Ae0B8QVt0_9CuM

    Best Regards,
    Weiwei


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, August 30, 2017 1:56 AM
  • Hi Weiwei,

    I downloaded the project but I'm unable to build it. When building, it returns the error:

    error VSSDK1000: Failed to load 'X:...\VCCodeModelSample\VCCodeModelSample\packages\Microsoft.VSSDK.BuildTools.15.1.192\tools\VSSDK\bin\VSCT.exe' Assembly. Could not load file or assembly 'file:///X:...\VCCodeModelSample\VCCodeModelSample\packages\Microsoft.VSSDK.BuildTools.15.1.192\tools\VSSDK\bin\VSCT.exe' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)

    Do you know what might be wrong?

    Thanks,

    Rich

    Wednesday, August 30, 2017 10:38 PM
  • Hi Rich,

    The Microsoft.VSSDK.BuildTools is a NuGet package for VSIX project. You could try reinstall it by right-click the project -> Choose Manage NuGet Packages to open the NuGet Package Manager and then search this package to reinstall.

    Please make sure the nuget.org package source is enabled. You could check it from Tools -> Options -> NuGet Package Manager -> Package Source.

    Best Regards,
    Weiwei


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Weiwei Cai Friday, September 1, 2017 5:09 AM
    Thursday, August 31, 2017 3:07 AM
  • Hi Weiwei,

    Thanks very much. It works!

    Now I can work on my project.

    Thanks,

    Rich

    Thursday, August 31, 2017 10:18 PM
  • Hi Rich,

    I'm glad that you have resolved your problem.

    Please mark the helpful reply as answer which is benefit to other communities who has the same problem.

    Best Regards,
    Weiwei


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, September 1, 2017 5:09 AM