Unable to cast COM object of type 'System.__ComObject' to class type RRS feed

  • Question

  • User1112784522 posted

     I recently upgraded a DLL from VB6 to .Net and am encountering a confusing error. This DLL is used as a reference in a .Net web application and now in certain locations in the application I am getting the following error:

    Unable to cast COM object of type 'System.__ComObject' to class type 'rjsDocMan.Folder'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.

    The code where it is flagging the error is:

    treeview += AddChildren(Session("DocMan").RootFolder)

    Whenever the error occurs it is simply manipulating some of the custom class objects that are defined in the DLL, however I am not sure what I need to do to get the error to go away. The code worked fine in VB6 so I'm assuming I need some additional code in the class definition now that it is in .Net?

    Any help would be greatly appreciated!

    Thursday, May 14, 2009 10:40 AM

All replies

  • User1112784522 posted

     All classes are in their own .vb files and all are marked as "COM Visible" being true. All classes are currently marked with "COM Class" set to False, however toggling "COM Class" to True does not fix the exception. These are the only settings I can see in the class properties related to COM...

    Has no one ever run into this error before updating a DLL from VB6? I find that hard to believe...

    Thursday, May 14, 2009 4:15 PM
  • User1112784522 posted

    Furthermore, the exception only occurs when an class object in the DLL is being assigned to a local variable in the web application. Calling methods from the class objects work perfectly fine.

    Thus, this works without problem:

    1    Session("DocMan").CurrentFolder.Documents.Refresh()
    but passing that object as a parameter or assigning it to a local variable throws the exception as noted above:
    1    AddChildren(Session("DocMan").RootFolder)
    1    childFolders = parentFolder.ChildFolders

    do not work.
    Thursday, May 14, 2009 5:05 PM
  • User1112784522 posted

     I've tried completely recreating the classes from scratch to see if some of the behind-the-scenes voodoo was simply not quite connecting, but no dice on that either.

    Any suggestions?

    Friday, May 15, 2009 9:45 AM
  • User1112784522 posted


    Wednesday, June 10, 2009 12:47 PM