Note that there are some explanatory texts on larger screens.

plurals
  1. PODTE: attempt to cast ProjectItem's Window.Document to a TextDocument throws exception
    primarykey
    data
    text
    <p>Carlos J. Quintero seems to know a lot about DTE. In an article updated in March of this year and published on the Web (<a href="http://www.mztools.com/articles/2007/mz2007027.aspx" rel="nofollow noreferrer">http://www.mztools.com/articles/2007/mz2007027.aspx</a>) he says that the Open method on an EnvDTE. ProjectItem returns an EnvDTE.Window, whose Document property can be cast to an EnvDTE.TextDocument.</p> <p>But when I try this, I get an exception (HRESULT: 0x80004002 [E_NOINTERFACE]). It seems that the __ComObject returned by Open doesn't know about TextDocument:</p> <p><img src="https://i.stack.imgur.com/H7tQO.jpg" alt="enter image description here"></p> <p>An (extracted and slightly edited) excerpt from my VB .Net code (VS2008 running under Windows 7 Pro 64 in WOW): </p> <blockquote> <p>...handler for BuildEvents.OnBuildBegin recursively traverses all items in all projects; filters names to find those containing ".Designer.vb" (apparently works fine to here). For each found, want to replace certain text; to do so, need TextDocument object:</p> </blockquote> <pre><code>'the below returns __ComObject instead of EnvDTE.Window Dim ItemWindow as EnvDTE.Window = ProjectItem.Open(EnvDTE.Constants.vsext_vk_Code) 'the below throws exception Dim ItemTextDocument as EnvDTE.TextDocument = CType(ItemWindow.Document, EnvDTE.TextDocument) </code></pre> <p>complete error:</p> <pre><code>Unable to cast COM object of type 'System.__ComObject' to interface type 'EnvDTE.TextDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{CB218890-1382-472B-9118-782700C88115}' failed due to the following error: Interface wordt niet ondersteund (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)). </code></pre> <p>What is wrong? Any help appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload