Select to view content in your preferred language

Weird Issue with onDeleteFeature event

554
2
Jump to solution
05-03-2019 06:52 AM
BrianBulla
Honored Contributor

Hi,

So I've written an Editor Extension which has some code that runs when a feature is deleted.  Everything works 100% as needed, but today I decided to add a few lines of code to track some information in a Share Point List when a feature gets deleted.  As soon as I add that code, none of the code within my onDeleteFeature event fires.  It's like it doesn't even exists.  But....as soon as I comment out the code I added, everything works fine.  Really weird.  I don't know what the heck is going on.

See below.  The code below works, but as soon as I uncomment the commented out section, nothing works.  i don't even get the message box to pop up.  If I debug, nothing in this entire code block runs, but the delete still happens in ArcMap.

Any ideas??

        //When a feature is Deleted.
        void Events_OnDeleteFeature(ESRI.ArcGIS.Geodatabase.IObject obj)
        {
            try
            {
                if (obj is IFeature)
                {
                    //Cast to an IFeature
                    IFeature inFeature = (IFeature)obj;                 
                    ITable inTable = obj.Table;

                    if (inTable is IVersionedObject)
                    {
                        IVersionedObject3 vObject = (IVersionedObject3)inTable;

                        //Check if the Features Table is Versioned.  If not, then exit.
                        if (vObject.IsRegisteredAsVersioned)
                        {
                            //Look for the Maximo field and edit.
                            if (inFeature.Fields.FindField("MXCREATIONSTATE") != -1)
                            {
                                MessageBox.Show("DELETE");
                                //using (SPSite spSite = new SPSite("https://...."))
                                //{
                                //    using (SPWeb spWeb = spSite.OpenWeb())
                                //    {
                                //        spWeb.AllowUnsafeUpdates = true;
                                //        SPList list = spWeb.Lists["GIS_Deletes"];

                                //        //Add an item
                                //        SPListItem newItem = list.Items.Add();
                                //        newItem["MXASSETNUM"] = inFeature.Fields.FindField("MXASSETNUM").ToString();
                                //        newItem["MXSITEID"] = inFeature.Fields.FindField("MXSITEID").ToString();
                                //        newItem.Update();

                                //        spWeb.AllowUnsafeUpdates = false;
                                //    }
                                //}
                            }                                                            
                        }                        
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error in OnDeleteFeature procedure.");
            }
            
        }
0 Kudos
1 Solution

Accepted Solutions
BrianBulla
Honored Contributor

Hi Duncan,

It took a while but I eventually figured out that I was just using the wrong NuGet package in VisualStudio.  Removing references and then using a different reference to the 2016 Microsoft SharePoint references seemed to fix the issue.

Thanks,

View solution in original post

0 Kudos
2 Replies
DuncanHornby
MVP Notable Contributor

I know nothing about share point but just for a sanity check could you put say a write to a simple text file in place of that code, so you know that code is executing in that block? If that works suspicion falls upon you SPSite and SPWeb objects.

0 Kudos
BrianBulla
Honored Contributor

Hi Duncan,

It took a while but I eventually figured out that I was just using the wrong NuGet package in VisualStudio.  Removing references and then using a different reference to the 2016 Microsoft SharePoint references seemed to fix the issue.

Thanks,

0 Kudos