Does anyone know what the ArcObjects reference library is for the IUnknown interface? I migrated the code below into Visual Studio and there is an error on the "Dim pSelItem As IUnknown" line.

ERROR 'IUknown' is not accessible in the context because it is 'Friend'

' Get the selected layer or table
        Dim pTable As ITable
        Dim pDispTab As IDisplayTable
        Dim pStAloneTab As IStandaloneTable
        Dim pSelItem As IUnknown
        pSelItem = m_pMxDoc2.SelectedItem 

I'm guessing I need to provide the full path reference for the Dim line? Maybe there is a newer interface that I can assign pSelItem to for .NET?


Maybe it should be "Dim pSelItem as Object", since the IMxDocument.SelectedItem Property for .NET accepts Object?

IMxDocument.SelectedItem Property link


1 Answer 1


You rarely need to access IUnknown in day-to-day AO development (or COM interop for that matter). Declaring your variable as object will do the trick since you will anyway need to cast it to another interface afterwards.

  • +1 But you can't forget about all COM details - sometimes ReleaseCOMObject is needed, which calls IUnknown.Release behind the scenes. Commented Jun 9, 2011 at 16:06
  • @Kirk: I see what you are getting at and agree on your point, but RelaseComObject does actually call IUnknown.Release. CLR manages the RCW's reference counter (conceptually different from COM reference counter) and only if that counter drops to zero, the CLR releases the single reference it holds to the actual COM object. Only then is IUnknown.Release called, but not by ReleaseComObject method, but the CLR interop infrastructure itself. Anyway, these are details developer almost never needs to worry about, but I just wanted to clear that up.
    – Petr Krebs
    Commented Jun 9, 2011 at 16:59
  • Yeah, it would be useful to have guidelines for folks migrating VB6 to vb.net. As I recall vb6, it is common practice to set variable = Nothing to trigger IUnknown.Release, but I don't think setting a .net variable to null has the same effect(?) Commented Jun 9, 2011 at 17:21
  • @Kirk: it does not have such direct effect in .NET.. COM objects references in .NET are released either via Marshal.ReleaseComObject (or Marshal.FinalReleaseComObject) or when their RCWs are garbage collected.
    – Petr Krebs
    Commented Jun 9, 2011 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.