AnsweredAssumed Answered

ShapefileWorkspaceFactory Failing In Arc 10

Question asked by geonetadmin on Apr 3, 2012
Latest reply on Jul 9, 2013 by GoogleGirl
Original User: jflorey

Hi All,

I am writing a utility using C# and Visual Studio 2010 that needs to create a connection to a workspace.  I have ArcGIS Desktop 10 Service Pack 2 installed.  I have tried two different ways to create a workspace:
In this function call, I pass in "esriDataSourcesFile.ShapefileWorkspaceFactory" as the factoryProgID parameter
        private static SingleValueResult<IWorkspace> OpenWorkspaceFromFile(string fullPath, string factoryProgID)
        {
            SingleValueResult<IWorkspace> result = new SingleValueResult<IWorkspace>();
            try
            {
                Type factoryType = Type.GetTypeFromProgID(factoryProgID);
                IWorkspaceFactory2 factory = (IWorkspaceFactory2)Activator.CreateInstance(factoryType);
                if (!object.Equals(null, factory))
                {
                    IWorkspace workspace = factory.OpenFromFile(fullPath, 0);
                    if (!object.Equals(null, workspace))
                    {
                        result.Success = true;
                        result.ReturnValue = workspace;
                    }
                }
                else
                    result.SetFailure(String.Format(
                        Properties.Resources.NullValueFailureFormat, "WorkspaceFactory"));
            }
            catch (Exception ex)
            {
                result.SetFailure(ex.Message);
            }
            return result;
        }

In this function call I try to spin up a ShapefileWorkspaceFactory directly:

        private static SingleValueResult<IWorkspace> OpenShapefileWorkspace(string fullPath)
        {
            SingleValueResult<IWorkspace> result = new SingleValueResult<IWorkspace>();
            IWorkspaceFactory factory = new ShapefileWorkspaceFactory();
            IWorkspace workspace = factory.OpenFromFile(fullPath, 0);
            if (!Equals(null, workspace))
            {
                result.Success = true;
                result.ReturnValue = workspace;
            }
            return result;
        }

In both cases I am getting the same failure:

{"Retrieving the COM class factory for component with CLSID {A06ADB96-D95C-11D1-AA81-00C04FA33A15} failed due to the following error: 80040111 ClassFactory cannot supply requested class (Exception from HRESULT: 0x80040111 (CLASS_E_CLASSNOTAVAILABLE))."}

In the code where I pass in a factoryProgID it fails on the line with Activator.CreateInstance.  In the code where I try to spin up the ShapefileWorkspaceFactory it fails on the line with new ShapefileWorkspaceFactory().

I have added a reference to ESRI.ArcGI.DataSourcesFile to my project and "using ESRI.ArcGIS.DataSourcesFile" to my code file.

This appears to be related to Arc 10, since I have successfully used very similar code in previous versions without problems.  Any assistance will be greatly appreciated.

Regards,
Jay

Outcomes