IName.Open issues with Shapefile Workspace (for dbf files)

Discussion created by fannonj on Aug 22, 2011

I am writing some code that uses IGxDialog to save an output dbf file. After the gxdialog is closed I am storing the gxObject.InternalObjectName (always either a file GDB, PGDB or shapefile workspace) as an IName so that I can open the workspace later:

IGxObject gxObject = gxDialog.FinalLocation;
if (gxObject != null)
      m_outputFeatureWSName = gxObject.InternalObjectName;
      m_outputTableName = gxDialog.Name;

However, when I later try to open the workspace using IName.Open() it works fine for file GDB and PGDB, but for shapefile workspace I get a Null reference when casting IName.Open() to an IWorkspace. I have even tried testing that the IName object is a WorkspaceName and then casting to an IWorkspaceName2, but this results in a COM error (see below).

if (name is WorkspaceName)
     IWorkspaceName2 wsName2 = (IWorkspaceName2)name; //COM ERROR HERE

     //Get the feature workspace to create the table within
     workspace = (IWorkspace)name.Open(); //this also returns Null if the above line is removed

This is the COM error:

Unable to cast COM object of type 'System.__ComObject' to interface type 'ESRI.ArcGIS.Geodatabase.IWorkspaceName'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{FADD975C-E36F-11D1-AA81-00C04FA33A15}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

I thought the whole idea behind IName objects is to store a reference to workspaces/datasets for later opening, so I'm confused as to why it doesn't work for shapefile workspaces. I'm also at a loss to explain why, if the IName is confirmed as a WorkspaceName as above, it won't cast to an IWorkspaceName2.

Can anyone confirm if this is a know bug - I have searched, but couldn't find anything relating to this behaviour. If anyone can offer a work-around that would also be great - all I want to do is store the workspace the user has selected in the gxDialog for saving a table to later.

My Environment is:

ArcGIS Desktop 9.3.1 build 3000 (ArcEditor EDN License)
Windows XP Pro SP3