locked
Upgrading VS08 VSIP to 2010 VSIX - Invalid Cast from IVsUIShellOpenDocument.OpenSpecificEditor() RRS feed

  • Question

  • Greetings,

    We have a Code Review Tool VSIP that we're upgrading to 2010. I upgraded it to .NET 4, added a VSIX manifest, changed all the references to point to v. 10.0 of the libraries, and things seemed to be going fine. Some of the screens work in 2010. However, trying to open our main editor, I get an Invalid Cast exception out of OpenSpecificEditor that I haven't been able to track down.

    Here's the relevant code in our class that implements IVSHierarchy, IVSUiHierarchy, IVSProject, etc:

      Public Function OpenItem(ByVal itemid As UInteger, ByRef rguidLogicalView As System.Guid, ByVal punkDocDataExisting As System.IntPtr, _
                   ByRef ppWindowFrame As Microsoft.VisualStudio.Shell.Interop.IVsWindowFrame) As Integer Implements Microsoft.VisualStudio.Shell.Interop.IVsProject.OpenItem
        Debug.WriteLine("OpenItem")
        ppWindowFrame = Nothing
        If _nodesbyid.ContainsKey(itemid) Then
          Dim node = _nodesbyid(itemid)
          ' show the document, set ppWindowFrame
          Dim frame As IVsWindowFrame = GetDocumentWindowFrame(node)
          If (frame Is Nothing) Then
            Dim empty As Guid = Guid.Empty
            Dim flags As UInteger = (__VSOSEFLAGS.OSE_UseOpenWithDialog Or _VSRDTFLAGS.RDT_DontAddToMRU) ' &H10010048
            Dim opendocument As IVsUIShellOpenDocument = CodeReviewToolsPackage.Instance.GetService(Of SVsUIShellOpenDocument, IVsUIShellOpenDocument)()
            ComUtils.ThrowOnFailure(opendocument.OpenSpecificEditor(flags, node.CanonicalName, _
                        node.EditorGuid, Nothing, empty, node.Caption, DirectCast(Me, IVsUIHierarchy), node.ItemId, _
                        punkDocDataExisting, DirectCast(CodeReviewToolsPackage.Instance, Microsoft.VisualStudio.OLE.Interop.IServiceProvider), frame))
    
            Dim docview As ICodeReviewToolsEditor
            ComUtils.ThrowOnFailure(frame.GetProperty(__VSFPROPID.VSFPROPID_DocView, docview))
            docview.WindowFrame = frame
            frame.Show()
            ppWindowFrame = frame
          Else
            frame.Hide() ' Make sure the activated event is thrown when we .Show()
            frame.Show()
            ppWindowFrame = frame
          End If
    
          Return VSConstants.S_OK
        Else
          Return VSConstants.E_FAIL
        End If
      End Function

    And the error that is thrown out of the ThrowOnFailure (The COM Result integer is -2147467262 if it matters):

    System.InvalidCastException

       at Microsoft.VisualStudio.Platform.WindowManagement.VariantHelpers.TryGetInt(Object var, Int32& value)

       at Microsoft.VisualStudio.Platform.WindowManagement.DocumentObjectSite.UpdateHierItemID(IntPtr hierPtr, UInt32 vid)

       at Microsoft.VisualStudio.Platform.WindowManagement.DocumentObjectSite..ctor(WindowFrame frame, IServiceProvider serviceProvider, Object docData, IVsUIHierarchy uiHierarchy, UInt32 itemID)

       at Microsoft.VisualStudio.Platform.WindowManagement.WindowManagerService.CreateContentPane(String pszName, Int32 fDockViewOn, Int32 fDocument, String lpstrMkDoc, UInt32 eCreateWindowFlags, UInt32 dwToolWinId, Object punkView, Object punkData, IServiceProvider pServiceProvider, IVsUIHierarchy pUIHierarchy, UInt32 vsid, Int32& pfDefaultPosition, Guid& rguidCmdUI, IVsWindowFrame& ppWindowFrame)

       at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)

       at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)

       at CodeReviewTools.ComUtils.ThrowOnFailure(Int32 result, Int32[] expectedHRFailure) in C:\...\CodeReviewTools\Package Plumbing\NativeMethods.vb:line 38

     

    I'm not sure what other info will be useful to tracking down this problem, so ask away if there's something else you need. Thanks in advance.

     

    - Josh Slosson

     

     

    Tuesday, April 20, 2010 2:21 PM

Answers

All replies

  • Hi Josh,

    Thanks for your post.

    Please check this thread as similiar problem as yours:

    Invalid Guid cast exception when opening custom VS editor migrated from VS2008 to VS2010

    To see if it works. And for your reference, please see MSDN article:

    Troubleshooting Exceptions: System.InvalidCastException

    As this article says: An InvalidCastException exception is thrown when a failure occurs during an explicit reference conversion.For an explicit reference conversion to be successful, the source value must be Null (Nothing in Visual Basic), or the object type referenced by the source argument must be convertible to the destination type by an implicit reference conversion.

    Hope this helps.

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Josh Slosson Wednesday, April 21, 2010 12:55 PM
    Wednesday, April 21, 2010 7:58 AM
  • Thanks for responding, Nancy.

     

    This indeed was a similar problem as the linked issue. Mine was not a Guid cast exception internally, but it was still a problem inside my GetProperty() implementation.

    Public Function GetProperty(ByVal itemid As UInteger, ByVal propid As Integer, ByRef pvar As Object) As Integer Implements ICodeReviewHierarchyNode.GetProperty
    
      Select Case propid
        ' other cases omitted here
        Case __VSHPROPID.VSHPROPID_ParentHierarchyItemid, __VSHPROPID.VSHPROPID_AltItemid
          'pvar = VSConstants.VSITEMID_NIL
          pvar = VSConstants.E_NOTIMPL
      End Select
      Return VSConstants.S_OK
    End Function
    By replacing the VSITEMID_NIL with the E_NOTIMPL, it worked fine. Many thanks!

    Wednesday, April 21, 2010 12:55 PM
  • Hi Josh,

    Glad to hear it works, Cheer!

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, April 22, 2010 1:46 AM