Error opening gdb workspace with FileGDBWorkspaceFactory

835
3
01-31-2023 01:35 AM
AleAlma
New Contributor II

Hello, i'm trying to open a gdb workspace from a path, but i keep getting an exception on invoking new FileGDBWorkspaceFactory(). The whole project was made by other people, i'm just trying to run it on my computer so the exact same code works just fine on some colleagues computers, i can't understand what's the actual problem. 

The function is really simple:

public static IWorkspace OpenFileGdbWorkspaceFromPath(String path)
{
IWorkspace oWS = null;

try
{
IWorkspaceFactory myworkspaceFactory = new FileGDBWorkspaceFactory();
oWS = myworkspaceFactory.OpenFromFile(path, 0);

}
catch (Exception ex)
{
//handles exception
}

return oWS;
}

And the exception is:

System.InvalidCastException: 'Impossibile eseguire il cast di oggetti COM di tipo 'System.__ComObject' in tipi di interfaccia 'ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactory'. L'operazione non è stata completata perché la chiamata QueryInterface sul componente COM per l'interfaccia con IID '{F173FC16-D63A-11D1-AA81-00C04FA33A15}' non è riuscita a causa del seguente errore: Interfaccia non supportata. (Eccezione da HRESULT: 0x80004002 (E_NOINTERFACE)).'

I'm not sure of what informations might be relevant, so please just ask me and i'll try to provide anything i can. Thank you very much

0 Kudos
3 Replies
BrentHoskisson
Occasional Contributor III

It can be difficult to fix an issue that works on one computer, but not another one.  It could be different ways that ArcMap was installed.  It could be different versions of ArcMap.  Or it could be in that user's profile.  Sometimes I will have the user log on to my computer and run it.  If it works, you may have to reinstall ArcMap on the other computer.  If it doesn't work, it could be a permissions issue.

 

Good Luck

Brent

AleAlma
New Contributor II

I'm still struggling with this project but reinstalling Arcmap was actually a good suggestion i didn't consider and i think it solved this specific error i was asking about. So thank you!

0 Kudos
gisweis2020
New Contributor

This is a very common AO development issue. FileGDBWorkspaceFactory is a singleton. Please use Activator.CreateInstance to initialize it. See my blog for details: https://www.cnblogs.com/liweis/p/17038824.html