Errors when creating a TextElement from ArcObjects

10-31-2013 06:31 AM
New Contributor
I am attempting to add some text in the layout view of ArcMap. I???m using the following line for the TextElement that I???ve found online from numerous places including ArcObjects Library Reference. Being new to ArcObjects, I'm not sure if I'm doing something wrong or if there is something else going on that I'm unaware of.

ITextElement textElement = new TextElementClass();

I'm receiving the following errors:

The type TextElementClass has no constructors defined
Interop type TextElementClass cannot be embedded. 

Full Code:

protected override void OnClick()
        IMxDocument mxDoc = ArcMap.Application.Document as IMxDocument;
        IMap map = mxDoc.FocusMap;
        IActiveView activeView = map as IActiveView;
        IPageLayout pageLayout = activeView as IPageLayout;

        if (activeView is IPageLayout)
            IGraphicsContainer graphContainer = pageLayout as IGraphicsContainer;
            ITextElement textElement = new TextElementClass(); 
            textElement.Text = "Test";
            IElement element = textElement as IElement;
            MessageBox.Show("This tool only functions in layout view");
0 Kudos
1 Reply
Regular Contributor III
Have you included all of the required ESRI assembly references in your project?  For a text element they are Carto, Geometry and System.  Also, if your project references the .NET Framework 4.0 be sure you set the Imbed Interop Types property to False for all of your ESRI assembly references.
0 Kudos