ShapefileWorkspaceFactory Failing In Arc 10

4175
5
04-03-2012 11:55 AM
by Anonymous User
Not applicable
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
0 Kudos
5 Replies
by Anonymous User
Not applicable
Original User: jflorey

Hi All,

An update to my original posting.  The code that tries to spin up the IWorkspaceFactory2 from a factory type (the first code snipped in my post) retrieved from a factoryProgID is also failing with esriDataSourcesGDB.AccessWorkspaceFactory and esriDataSourcesGDB.FileGDBWorkspaceFactory as the ProgID value.

Regards,
Jay
0 Kudos
NeilClemmons
Regular Contributor III
When you say utility, do you mean this is a standalone application or is it running inside ArcMap?
0 Kudos
by Anonymous User
Not applicable
Original User: jflorey

Hi Neil,

It's running as a standalone application.  I have two separate entry points, and I think the problem might be that I am not binding to a license in the entry point from which I'm getting the failure.  I have to solve another issue with Visual Studio crashing before I can test my theory.

Thanks for the response.

Jay
0 Kudos
by Anonymous User
Not applicable
Original User: jflorey

Hi All,

It turned out that all attempts to access ArcObjects were failing with the same error message.  The cause was that I had forgotten to bind to a license in the standalone entry point.  Adding a license binding fixed the problem.

Regards,
Jay
DebbieAlger
New Contributor III
Hi, I am getting the same problem for day, very annoying. I have added binding to Engine license at the start of my application, but   still getting that error on every instance of x = new x.  Please explain exactly what and where you made the fix.

thanks
0 Kudos