[英]How to cast ComObject to ENVDTE.Project?
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. 我尝试按此处所述注册DLLS,但似乎还有其他问题。
Found the solution. 找到了解决方案。 Some hashtable entries had ENVDTE.ProjectItems as value.
一些哈希表条目具有ENVDTE.ProjectItems作为值。 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));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.