Problem with disappearing class extension.

617
3
06-14-2011 04:59 AM
New Contributor
Hi all,

my English isn't very good, but I hope you will understand me 🙂
I'm quite new in ESRI tools, ArcObject's and so on. At this moment we (at work) started changing ArcGis 9.3 to 10. Everything has been OK so far. But now there is one problem - Class Extension. Adding and removing I've done, but... not really. Let me explain this:
I log in and then I use my command button to add (I use IClassSchemaEdit2.AlterClassExtensionCLSID() method) class extansion to selected tables. I verify that and there is what I added. But problem begins when I turn off ArcCatalog and then I turn it on once again. All added Class extansions disappeared! Why? In ArcGIS 9.3 it was easier, because one insert into appropirate table and class extension is remembered.


PS.
With Workspace Extension there aren't any problems like with Class Extension.
Reply
0 Kudos
3 Replies
New Contributor
Hi all,

my English isn't very good, but I hope you will understand me 🙂
I'm quite new in ESRI tools, ArcObject's and so on. At this moment we (at work) started changing ArcGis 9.3 to 10. Everything has been OK so far. But now there is one problem - Class Extension. Adding and removing I've done, but... not really. Let me explain this:
I log in and then I use my command button to add (I use IClassSchemaEdit2.AlterClassExtensionCLSID() method) class extansion to selected tables. I verify that and there is what I added. But problem begins when I turn off ArcCatalog and then I turn it on once again. All added Class extansions disappeared! Why? In ArcGIS 9.3 it was easier, because one insert into appropirate table and class extension is remembered.


PS.
With Workspace Extension there aren't any problems like with Class Extension.


Hi,
I too work with ClassExtensions but your reported problem sounds weird. Can you post your code that you are using to install the class extension?
I got similar problem but with Updating the code that works for Class Extensions, its working fine when I install the class extensions using ArcCatalog's Add-In Button but when I open ArcMap having the classes that got the class extensions, I did not see any updated version of Class extensions.
Then I found that there is another Application Extension that I developed on ArcMap that has the reference of Class Extensions and I forgot to rebuild that Application Extension solution, so that's the reason it loads the old class extension code rather than the updated one while its starting.

SO I suggest you to check are there any other Applications that have the reference of the class extensions you are working with.
Did you check the schema lock stuff?
It seems like when your ArcCatalog get closed, your class extensions are getting removed.
I always prefer to include a logfile in the project, so I can see exactly whats going on..
So you might have ArcObjects project for Class Extensions and the other Button to install them, right?
Anyways, FYI:
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Creating_class_extensio...
Reply
0 Kudos
New Contributor
Thanks syamarth for reply.

My code looks like this:

1. First I get all selected items in ArcCatalog
            IGxApplication gxApp = m_application as IGxApplication;
            IGxSelection gxSel = null;
            IEnumGxObject enumGxObj = null;
            IGxObject gxObj = null;
           
            gxSel = gxApp.Selection;
            enumGxObj = gxSel.SelectedObjects;
            gxObj = enumGxObj.Next();
            while (gxObj != null)
            {
                Tools.AddRemoveExtension(gxObj, true, "{32B73670-FF7E-4e52-A0D2-740716E011D1}");
                gxObj = enumGxObj.Next();
            }


In Tools class I have all methodes I use to setting extension.

2. In AddRemoveExtension method I check if selected item is appropriate and then I try to get IObjectClass object:

        public static void AddRemoveExtension(IGxObject gxObj, bool add_remove, string GUID)
        {
...                        
                IGxDataset pGxDataSet = gxObj as IGxDataset;
               
                IDataset pDataSet = pGxDataSet.Dataset;
                IObjectClass pObjectClass = pDataSet as IObjectClass;

                if(pObjectClass != null && !gxObj.Name.ToUpper().Contains("GEODB.TS_"))
                    try
                    {
                        ChangeClassExtension(pObjectClass, GUID, null, add_remove);
                    }
                    catch(Exception e)
                    {
                        System.Windows.Forms.MessageBox.Show(errorMsg);
                    }           
        }


3. After that I use method found by me in ESRI help (the same page you gave me in your post above)

        private static void ChangeClassExtension(IObjectClass objectClass, String extensionUID, IPropertySet extensionProperties, bool add_remove)
        {
            ISchemaLock schemaLock = (ISchemaLock)objectClass;

            try
            {
                // Attempt to get an exclusive schema lock.
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

                // Cast the object class to the IClassSchemaEdit2 interface.
                IClassSchemaEdit2 classSchemaEdit = (IClassSchemaEdit2)objectClass;

                if (!String.IsNullOrEmpty(extensionUID) && add_remove == true)
                {
                    // Create a unique identifier (UID) object and change the extension.
                    UID extUID = new UIDClass();
                    extUID.Value = extensionUID;
                    classSchemaEdit.AlterClassExtensionCLSID(extUID, extensionProperties);
                }
                else
                {
                    // Clear the class extension.
                    classSchemaEdit.AlterClassExtensionCLSID(null, null);
                }
            }
            catch (COMException comExc)
            {
                throw new Exception("Could not change class extension.", comExc);
            }
            finally
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }
        }


And yes - I have separated project with ClassExtension and the other one with all buttons to adding/removing ClassExtension and WorkspaceExtension.
I think there aren't any other Applications that have reference of this Class Extension.
Reply
0 Kudos
New Contributor
Thanks syamarth for reply. 

My code looks like this: 

1. First I get all selected items in ArcCatalog 
            IGxApplication gxApp = m_application as IGxApplication;
            IGxSelection gxSel = null;
            IEnumGxObject enumGxObj = null;
            IGxObject gxObj = null;
           
            gxSel = gxApp.Selection;
            enumGxObj = gxSel.SelectedObjects;
            gxObj = enumGxObj.Next();
            while (gxObj != null)
            {
                Tools.AddRemoveExtension(gxObj, true, "{32B73670-FF7E-4e52-A0D2-740716E011D1}");
                gxObj = enumGxObj.Next();
            }


In Tools class I have all methodes I use to setting extension. 

2. In AddRemoveExtension method I check if selected item is appropriate and then I try to get IObjectClass object: 

        public static void AddRemoveExtension(IGxObject gxObj, bool add_remove, string GUID)
        {
...                        
                IGxDataset pGxDataSet = gxObj as IGxDataset;
               
                IDataset pDataSet = pGxDataSet.Dataset;
                IObjectClass pObjectClass = pDataSet as IObjectClass;

                if(pObjectClass != null && !gxObj.Name.ToUpper().Contains("GEODB.TS_"))
                    try
                    {
                        ChangeClassExtension(pObjectClass, GUID, null, add_remove);
                    }
                    catch(Exception e)
                    {
                        System.Windows.Forms.MessageBox.Show(errorMsg);
                    }           
        }


3. After that I use method found by me in ESRI help (the same page you gave me in your post above) 

        private static void ChangeClassExtension(IObjectClass objectClass, String extensionUID, IPropertySet extensionProperties, bool add_remove)
        {
            ISchemaLock schemaLock = (ISchemaLock)objectClass;

            try
            {
                // Attempt to get an exclusive schema lock.
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

                // Cast the object class to the IClassSchemaEdit2 interface.
                IClassSchemaEdit2 classSchemaEdit = (IClassSchemaEdit2)objectClass;

                if (!String.IsNullOrEmpty(extensionUID) && add_remove == true)
                {
                    // Create a unique identifier (UID) object and change the extension.
                    UID extUID = new UIDClass();
                    extUID.Value = extensionUID;
                    classSchemaEdit.AlterClassExtensionCLSID(extUID, extensionProperties);
                }
                else
                {
                    // Clear the class extension.
                    classSchemaEdit.AlterClassExtensionCLSID(null, null);
                }
            }
            catch (COMException comExc)
            {
                throw new Exception("Could not change class extension.", comExc);
            }
            finally
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }
        }


And yes - I have separated project with ClassExtension and the other one with all buttons to adding/removing ClassExtension and WorkspaceExtension. 
I think there aren't any other Applications that have reference of this Class Extension.


Hi,
I've tested your code with an Add-in button on Catalog.
I found that IGxApplication.Selection will have the selected objected only from the Tabbed view.
Because, when I debug the code, the Selection has 0 count thought I select an object class from the Tree view of the catalog. But if change my selection of the object class from Treeview to the tabbled view, the selection has the count 1 and then the class extensions got installed. They were still there after I closed and reopened the catalog.

I think you got the sample code of this IGxApplication.Selection from this:

then its mentioned before the code starts:
"The following code demonstrates how to loop through the selected objects in the tabbed view and print their categories"

so I suggest you to observe how your code is working at IGxApplication.Selection while you debug it.
Reply
0 Kudos