locked
Can not cast object of type VCProjectShim to type VCProject RRS feed

  • Question

  • I use the Package way to develop plug-ins in VS2015,
    The referenced assemblies are:
    Microsoft.VisualStudio.Shell.11.0;
    Microsoft.VisualStudio.Shell.Interop.10.0;
    Microsoft.VisualStudio.Shell.Interop.11.0;
    Microsoft.VisualStudio.Shell.Interop.8.0;
    Microsoft.VisualStudio.Shell.Interop.9.0;
    EnvDTE;
    EnvDTE100;
    EnvDTE80;
    EnvDTE90;
    Microsoft.VisualStudio.VCProject;
    Microsoft.VisualStudio.VCProjectEngine;

    Code:

    public static void AddCppIncludeDir(EnvDTE.Project p){

       VCProject vcp = (VCProject)p.Object; //Error:Can not cast object of type "Microsoft.VisualStudio.Project.VisualC.VCProjectEngine.VCProjectShim" to type "Microsoft.VisualStudio.VCProjectEngine.VCProject"

    }

    Wednesday, December 27, 2017 10:39 AM

Answers

All replies

  • Microsoft.VisualStudio.Project.VisualC.VCProjectEngine.VCProjectShim

    Where can I find this dynamic library;

    Wednesday, December 27, 2017 11:07 AM
  • Hi,

    Based on the following thread, it seems that cast CodeModel to a different VCCodeModel version. There is a VCCodeModel.dll for each VS version.

    You could also check the reply comments, which provide a workaround that define the types as object and rely on late binding.

    https://stackoverflow.com/questions/13850291/unable-to-cast-dte-project-or-solution-to-vcproject-and-vccodemodel

    Best regards,

    Zhanglong Wu


    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.

    Thursday, December 28, 2017 5:29 AM