Exception from IDataset.get_Workspace().

573
1
02-06-2013 12:44 AM
MikaelRittri
New Contributor
Hello,
I have begun to work on a prototype of a plugin to ArcMap 10.1. It works on our computers and for some customers, but other customers get an exception. 

Exception message:

[INDENT]Error HRESULT E_FAIL has been returned from a call to a COM component.[/INDENT]

Top of call stack:

[INDENT]at ESRI.ArcGIS.Geodatabase.IDataset.get_Workspace()[/INDENT]

The C# code that triggers the exception is probably

[INDENT]
IDataLayer2 dataLayer = ...
IDataset dataset = dataLayer as IDataset;
try
{
[INDENT]  if (dataset != null
[INDENT]        && dataset.Category == "Shapefile Feature Class"
                    && dataset.Workspace.Type == esriWorkspaceType.esriFileSystemWorkspace)
[/INDENT]
                {
                ...
                }[/INDENT]
}
catch (Exception e)
{
...
}

[/INDENT]

So, it seems that the call to dataset.Workspace.Type throws an exception. What could cause that?

I noticed that there is a boolean method I could have called,

[INDENT]
if (dataset.Workspace.Exists())

[/INDENT]

but if I get an exception just by getting the Workspace, I assume that I would never reach the Exists() method.
And I don't see what non-existence means. Is it the same as "file not found"?

I would be grateful for any help.
0 Kudos
1 Reply
RichardWatson
Frequent Contributor
One scenario that can happen is that the source of a layer can be unavailable, i.e. a "broken layer".

This would happen if say a user sends you a map document which points to a database (or data source) which you don't have.  In this case you can either fix the layer in ArcMap (e.g. point it to the correct source) or just leave it.

Regardless, your software has to anticipate and deal with this situation.
0 Kudos