2

I am using the following code :

Object projObj = htProjects[selectedNode]; // htProjects is a Hashtable:key-project Name,value-ENVDTE.Project
Project selectedProject = (Project)projObj; 

I am getting the following error :

Unable to cast COM object of type 'System.__ComObject' to interface type 'EnvDTE.Project'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{866311E6-C887-4143-9833-645F5B93F6F1}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

I tried registering DLLS as mentioned here but there seems to be some other issue.

Community
  • 1
  • 1
semantic_c0d3r
  • 819
  • 2
  • 15
  • 31

1 Answers1

6

Found the solution. Some hashtable entries had ENVDTE.ProjectItems as value. So a check was needed.

Code:

        if (projObj is Project)
        {
            Project selectedProject = (Project)projObj;
            MessageBox.Show(selectedProject.FullName);
        }
        else if(projObj is ProjectItem)
        {
            ProjectItem selectedProject = (ProjectItem)projObj;
            MessageBox.Show(selectedProject.get_FileNames(1));
        }
semantic_c0d3r
  • 819
  • 2
  • 15
  • 31