Search code examples
c#arcgisesriarcobjects

"ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass" cannot be embedded


I made an add in application for arcmap in C# and I tried to connect with my File Geodatabase. So when I tried to run it I got this error:

Error 1 Interop type 'ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass' cannot be embedded. Use the applicable interface instead.  

and then the path of the add in

I have never seen this error before and I was wondering what is going wrong.

This is the main code it's all about:

 public IWorkspace FileGdbWorkspaceFromPropertySet(string database)
    {
        IPropertySet propertySet = new PropertySetClass();
        propertySet.SetProperty("DATABASE", database);
        IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass();
        return workspaceFactory.Open(propertySet, 0);
    }

So the error is at this line:

IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass();

I hope someone can provide me an explanation of this error and also a possible fix in my case.

What is going wrong?


Solution

  • You may try to remove Class suffix. Replace

    IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass();

    with

    IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactory();

    Here https://stackoverflow.com/a/958952/1017722 Michael Petrotta's answer explains why.

    Here are similar answers: Interop type cannot be embedded, Class cannot be embedded. Use the applicable interface instead.