【问题标题】:How to cast ComObject to ENVDTE.Project?如何将 ComObject 转换为 ENVDTE.Project?
【发布时间】:2013-01-12 08:47:47
【问题描述】:

我正在使用以下代码:

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

我尝试按照here 的说明注册 DLLS,但似乎还有其他问题。

【问题讨论】:

    标签: c# envdte


    【解决方案1】:

    找到了解决方案。一些哈希表条目将 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));
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-17
      • 2010-09-08
      相关资源
      最近更新 更多