The following code
varpane = FrameworkApplication.DockPaneManager.Find("esri_editing_AttributesDockPane");
pane.Pin();
pane.Activate(true);
Will throw the following exception
System.AggregateException HResult=0x80131500 Message=A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. Source=mscorlib StackTrace: at System.Threading.Tasks.TaskExceptionHolder.Finalize() Inner Exception 1: NullReferenceException: Object reference not set to an instance of an object.
Not one single line will cause the issue. It's like the code queue's up some tasks and when they run, it will delayed fail. Upon further inspection, the calling code does nothing, but when trying to open the pane it will then throw.
The same thing seems to happen if the pane is visible if I comment out `Pin()` and/or `Activate(true)` it will still throw.
I've had similar experience with using the show attributes button command.
What is the proper way to display the attributes for a feature that has just been created so the user can directly start editing?
Solved! Go to Solution.
I'm still not seeing any problems. Here is a button click with a similar scenario to what you outlined - creating a feature with null geometry. I never see "boo" in a message box or get an exception.
What version of Pro are you using?. Is there anything particular about your data or the way you're calling the feature creation?
protected override async void OnClick()
{
bool result = await QueuedTask.Run(async () =>
{
FeatureLayer featureLayer = MapView.Active.Map.FindLayers("Point_Paired").FirstOrDefault() as FeatureLayer;
if (featureLayer == null)
return false;var editOperation = new EditOperation();
var atts = new Dictionary<string, object>();
// create with empty attributes - no shape
editOperation.Create(featureLayer, atts);bool creationResult = await editOperation.ExecuteAsync();
if (editOperation.IsSucceeded)
{
Application.Current.Dispatcher.Invoke(() =>
{
var pane = FrameworkApplication.DockPaneManager.Find("esri_editing_AttributesDockPane");
if (pane != null)
{
pane.Pin();
pane.Activate();
}
else
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("boo");
});
}return creationResult;
});}
Steve,
Make sure you are on the UI thread (ie not on the background thread) when you call DockPaneManager.Find. Dockpanes are created on the UI thread and should not be accessed on the CIM / background thread. I suspect this is why you are having this problem.
Narelle
Oh ok. I have been using the intellisense to know when something needs to run on the UI thread or the CIM thread as some things do mention that.
Although
Application.Current.Dispatcher.Invoke(() => {
var edits = FrameworkApplication.DockPaneManager.Find("esri_editing_AttributesDockPane");
edits.Activate(true);
edits.Pin();
});
Throws the same error.
The error is thrown if you create an edit operation, create a new row, my example has no geometry, and then run the code above in a isSucceeded if statement.
operation.Create(layer, attributes);
await operation.ExecuteAsync();
if (operation.IsSucceeded) {
// run code above and error is thrown.
}
I'm still not seeing any problems. Here is a button click with a similar scenario to what you outlined - creating a feature with null geometry. I never see "boo" in a message box or get an exception.
What version of Pro are you using?. Is there anything particular about your data or the way you're calling the feature creation?
protected override async void OnClick()
{
bool result = await QueuedTask.Run(async () =>
{
FeatureLayer featureLayer = MapView.Active.Map.FindLayers("Point_Paired").FirstOrDefault() as FeatureLayer;
if (featureLayer == null)
return false;var editOperation = new EditOperation();
var atts = new Dictionary<string, object>();
// create with empty attributes - no shape
editOperation.Create(featureLayer, atts);bool creationResult = await editOperation.ExecuteAsync();
if (editOperation.IsSucceeded)
{
Application.Current.Dispatcher.Invoke(() =>
{
var pane = FrameworkApplication.DockPaneManager.Find("esri_editing_AttributesDockPane");
if (pane != null)
{
pane.Pin();
pane.Activate();
}
else
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("boo");
});
}return creationResult;
});}
this hasn't happened for a while. I will mark it as answered. Thank you