IWorkspaceFactory factory = new CadWorkspaceFactoryClass (); IWorkspace workspace = factory.OpenFromFile(fileName, 0); // Throw exception
Never use New to create an instance of a singleton object like a workspace factory. Always use the Activator class. Also, is this a standalone application? If so, are you binding to a product then checking out a license before running this code?
Type factoryType = Type.GetTypeFromProgID( "esriDataSourcesFile.CadWorkspaceFactory"); System.Object obj = Activator.CreateInstance(factoryType); IWorkspaceFactory factory = obj as IWorkspaceFactory; IFeatureWorkspace workspace = (IFeatureWorkspace)factory.OpenFromFile(dgnFilePath, 0);
Any news?????
Hello, I had the same issue with reading DWG files using custom SOE and managed to solve it. It turned out that the OpenFromFile() method must be called with directory path not the file path as argument.
So instead of:
IWorkspace workspace = factory.OpenFromFile(fileName, 0);
Try with this:
string directoryName = fileName.Substring(0, fileName.LastIndexOf('\\'));
IWorkspace workspace = factory.OpenFromFile(directoryName, 0);