I am writing an ESRI addin (in c#) where in_memory layers are used. When the user opens the map document and activates the tool, the tool checks whether the in_memory layer is valid or not, and if it is not valid (has a red exclamation mark) it should delete the layer and recreate it for the current session.
I am using the following to delete the layer
but once it deletes it i then get a message box saying:
Object not set to an instance of an object
I have tried to disconnect the layer before I delete it using IDataLayer2.Disconnect
IFeatureLayer toDelete = dsAOI as IFeatureLayer; IDataLayer2 dl2 = toDelete as IDataLayer2; dl2.Disconnect();
but that results in the error message:
Error HRESULT E_FAIL has been returned from a call to a COM component
Has anyone got ideas on what I might be doing wrong, or a better way to get round this.