Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将ComObject强制转换为ENVDTE.Project?_C#_Envdte - Fatal编程技术网

C# 如何将ComObject强制转换为ENVDTE.Project?

C# 如何将ComObject强制转换为ENVDTE.Project?,c#,envdte,C#,Envdte,我正在使用以下代码: Object projObj = htProjects[selectedNode]; // htProjects is a Hashtable:key-project Name,value-ENVDTE.Project Project selectedProject = (Project)projObj; 我得到以下错误: Unable to cast COM object of type 'System.__ComObject' to interface type '

我正在使用以下代码:

Object projObj = htProjects[selectedNode]; // htProjects is a Hashtable:key-project Name,value-ENVDTE.Project
Project selectedProject = (Project)projObj; 
我得到以下错误:

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)).

我试着注册了前面提到的DLL,但似乎还有其他问题。

找到了解决方案。某些哈希表条目将ENVDTE.ProjectItems作为值。所以需要检查一下

代码:

        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));
        }