Loko
Loko

Reputation: 6679

"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?

Upvotes: 6

Views: 2814

Answers (2)

Evgeny Timoshenko
Evgeny Timoshenko

Reputation: 3259

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.

Upvotes: 0

aturns
aturns

Reputation: 41

Looks like the ESRI dll was embedded in your assemly. Assuming you are working with Visual Studio - Select the referenced dll, and in its properties set "Embed Interop Types" to False.

Note that this will create an interop file for that DLL which you will need to put next to your assembly.

Upvotes: 2

Related Questions