Hi all,
I was trying to add halo effect to an annotation layer, when I was trying to updating the symbol properties of ITextElement, the following error prompted:
System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component. at ESRI.ArcGIS.Carto.ITextElement.set_Symbol(ITextSymbol Symbol
I have no clue on what I've done wrong. Anyone can help me to find out what's the problem? any suggestion will be appreciated.
TextElement pTextElement = pAnnoFeat.Annotation as TextElement; ITextElement pElmt = pTextElement as ITextElement; ITextSymbol pTextSym = pElmt.Symbol; // simple line symbol ISimpleLineSymbol pLineSym = new SimpleLineSymbol(); pLineSym.Style = esriSimpleLineStyle.esriSLSNull; // Fill symbol IFillSymbol pFillSymbol = new SimpleFillSymbol(); pFillSymbol.Outline = pLineSym; pFillSymbol.Color = Converter.ToRGBColor(Color.Blue); // IMask IMask pMask = pTextSym as IMask; pMask.MaskSize = 10; pMask.MaskStyle = esriMaskStyle.esriMSHalo; pMask.MaskSymbol = pFillSymbol; pTextSym = pMask as ITextSymbol; pElmt.Symbol = pTextSym; // <-- this is where error occurred pAnnoFeat.Annotation = pElmt as IElement;
Answering this question so that it might be helpful for other users having similar question.
The potential reason is that the annotation might be store in geodatabase and one should not control the display by ItextElement::Symbol property. Instead use ISymbolCollectionElement. Below is the related documentation on this topic.
ArcObjects Help for .NET developers
---http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#//001w000003vt000000
"If you are editing Geodatabase Annotation, DO NOT control the display of annotation features by obtaining a reference to the TextSymbol through ITextElement::Symbol and change the properties. This will undermine the storage mechanism that Geodatabase Annotation utilizes for efficient storage. For more information on TextSymbols and Geodatabase Annotation, see the interface ISymbolCollectionElement."