Reputation: 1
I am currently developing using ArcObects 10.2.1 and I've encountered this tricky exception:
AccessViolationException was encountered
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source=System.Windows.Forms
StackTrace:
System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
System.Windows.Forms.Control.DefWndProc(Message& m)
System.Windows.Forms.Control.WndProc(Message& m)
System.Windows.Forms.AxHost.WndProc(Message& m)
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
InnerException:
I tried to annotate the code and find out where it was wrong,I found it's in the last line.but I still don't know how to solve it.
public void SetSimpleLabel(IFeatureLayer featLayer, string field, string where = "")
{
IGeoFeatureLayer geoFeatureLayer = featLayer as IGeoFeatureLayer;
IAnnotateLayerPropertiesCollection annoProperties = geoFeatureLayer.AnnotationProperties;
annoProperties.Clear();
ILineLabelPosition position = new LineLabelPosition();
position.Parallel = true;
position.Perpendicular = false;
ILineLabelPlacementPriorities placement = new LineLabelPlacementPriorities();
IBasicOverposterLayerProperties basic = new BasicOverposterLayerProperties();
basic.FeatureType = esriBasicOverposterFeatureType.esriOverposterPoint;
basic.LineLabelPlacementPriorities = placement;
basic.LineLabelPosition = position;
ILabelEngineLayerProperties labelProperties = new LabelEngineLayerProperties() as ILabelEngineLayerProperties;
labelProperties.Symbol = sf.CreateTextSymbol(null, 12, null, null, esriTextHorizontalAlignment.esriTHACenter);
labelProperties.BasicOverposterLayerProperties = basic;
labelProperties.Expression = "[" + field + "]";
IAnnotateLayerProperties annoLayerProperties = labelProperties as IAnnotateLayerProperties;
if (where != "")
annoLayerProperties.WhereClause = where;
annoProperties.Add(annoLayerProperties);
geoFeatureLayer.DisplayAnnotation = true; //it cause
}
why does it cause the exception?Does anybody have any ideas?
Upvotes: 0
Views: 295