我目前正在使用 ArcObects 10.2.1 进行开发,但遇到了这个棘手的异常:
遇到 AccessViolationException
尝试读取或写入受保护的内存。这通常表明其他内存已损坏。
源=System.Windows.Forms
堆栈跟踪:
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)
内部异常:
我尝试注释代码并找出错误的地方,我发现它在最后一行。但我仍然不知道如何解决它。
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
}
为什么会导致异常?有人有什么想法吗?