I am attempting to use the .SortByName() and .SortByValue() methods of the interface ICodedValueDomain2.

I use the same extension methods from an IWorkspace, however if I open the IWorkspace from an .sde connection file and try to cast the domain to an ICodedValueDomain2, I get the exception:

Unable to cast COM object of type 'System.__ComObject' to interface type 'ESRI.ArcGIS.Geodatabase.ICodedValueDomain2'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{057E88C6-0E61-426E-B4BB-D192C481CF1F}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

// *** Extension Methods ***

//This Method Works With .sde files and through ArcMap
public static ICodedValueDomain GetCodedValueDomain(this IWorkspace pWorkspace, string pName)
    IWorkspaceDomains workspaceDomains = (IWorkspaceDomains)pWorkspace;
    IDomain domain = workspaceDomains.get_DomainByName(pName);
    ICodedValueDomain codedValueDomain = (ICodedValueDomain)domain;
    return codedValueDomain;

//This Method does not work with .sde files, only through ArcMap
public static ICodedValueDomain2 GetCodedValueDomain2(this IWorkspace pWorkspace, string pName)
    IWorkspaceDomains2 workspaceDomains = (IWorkspaceDomains2)pWorkspace;
    IDomain domain = workspaceDomains.DomainByName[pName];
    ICodedValueDomain2 codedValueDomain = (ICodedValueDomain2)domain;
    return codedValueDomain;

// *** Workspace Retrieval ***

//Cannot use .GetCodedValueDomain2()
private static IWorkspace WorkspaceFromSDEFile(string pPath)
    SdeWorkspaceFactory wsFactory = new SdeWorkspaceFactory();
    IWorkspace ws = wsFactory.OpenFromFile(pPath, 0);
    return ws;

//Can use .GetCodedValueDomain2()
private static IWorkspace WorkspaceFromArcMap()
    IWorkspace ws = ((IDataset)((IFeatureLayer)ArcMap.Document.FocusMap.get_Layer(0)).FeatureClass).Workspace;
    return ws;

Why would the IWorkspace returned from wsFactory.OpenFromFile() not implement this interface, but the IWorkspace retrieved from the map does?

Here is the ArcObjects documentation for the ICodedValueDomain2 interface, present since 10.1: http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/#/ICodedValueDomain2_Interface/002500000nrt000000/

  • Have you seen this page? – Hornbydd Mar 22 '17 at 20:48
  • Yes, and I am doing all of that with success (it uses ICodedValueDomain). However, when I attempt to cast the IDomain to ICodedValueDomain2 instead of ICodedValueDomain to use the .SortByName() method, I get an exception that the interface is not supported when using an .sde file, but not when connecting through ArcMap. – Ehryk Mar 22 '17 at 21:00
  • Can you cast IDomain to ICodedValueDomain thence to ICodedValueDomain2? Perhaps the implicit conversion isn't working... but I think not. It sounds like your SDE workspace (or is it Versioned Workspace) domains aren't built with support for ICodedValueDomain2. What are your goals with sorting? Perhaps if you copy the values to a List and sort that it might do what you want. – Michael Stimson Mar 22 '17 at 22:23
  • @MichaelMiles-Stimson I can do just that cast when I open a workspace from ArcMap, but not from an .sde. They are the same domains in the same database, accessed two different ways - one succeeds (as an ArcMap plugin), one fails (as a console application). – Ehryk Mar 22 '17 at 22:47
  • That is really weird. Perhaps it's a validation thing.. is your username and password set to an enabled user in your IPropertySet? Is your user/pass saved in your SDE connection file? Is you standalone application calling the license initializer properly? – Michael Stimson Mar 22 '17 at 23:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.