Select to view content in your preferred language

100.3.0 Graphic Attributes Bug

1140
3
Jump to solution
08-23-2018 10:25 AM
Mike_Quetel
Frequent Contributor

If I create an instance of  Esri.ArcGISRuntime.UI.Graphic and add an attribute to it, in which the value of the attribute is a member of an enum, the graphic will not be successfully added to the graphics collection of an overlay.  It fails silently and and I'll see this in the output window at debug time:  

Exception thrown: 'System.NotSupportedException' in Esri.ArcGISRuntime.dll
Error: 'Specified method is not supported.'

Code that doesn't work:

var sketchGraphic = new Esri.ArcGISRuntime.UI.Graphic(geometry, symbol);
sketchGraphic.Attributes.Add(_adHocGraphicTypeAttributeName, AdHocGraphicTypeEnum.UserSketch);
sketchOverlay.Graphics.Add(sketchGraphic);

Code that does work:

var sketchGraphic = new Esri.ArcGISRuntime.UI.Graphic(geometry, symbol);
sketchGraphic.Attributes.Add(_adHocGraphicTypeAttributeName, 1);
sketchOverlay.Graphics.Add(sketchGraphic);

The enum above is defined as:

public enum AdHocGraphicTypeEnum
{
   Unknown = 0,
   UserSketch = 1,
   Buffer = 2
}

0 Kudos
1 Solution

Accepted Solutions
JenniferNery
Esri Regular Contributor

Attributes in v100.x only support the following data types https://developers.arcgis.com/net/latest/wpf/api-reference//html/T_Esri_ArcGISRuntime_Data_FieldType... with the exception of Geometry, Xml, Raster, Blob.

If you have a user-defined enum, you can cast it to int to allow you to store it in graphic.Attribute.

graphic.Attributes[_adHocGraphicTypeAttributeName] = (int)AdHocGraphicTypeEnum.UserSketch;

and evaluate its value by casting it back to the enum type.

if( (AdHocGraphicTypeEnum) graphic.Attributes[_adHocGraphicTypeAttributeName]  == AdHocGraphicTypeEnum.UserSketch) {...}

View solution in original post

3 Replies
JenniferNery
Esri Regular Contributor

Attributes in v100.x only support the following data types https://developers.arcgis.com/net/latest/wpf/api-reference//html/T_Esri_ArcGISRuntime_Data_FieldType... with the exception of Geometry, Xml, Raster, Blob.

If you have a user-defined enum, you can cast it to int to allow you to store it in graphic.Attribute.

graphic.Attributes[_adHocGraphicTypeAttributeName] = (int)AdHocGraphicTypeEnum.UserSketch;

and evaluate its value by casting it back to the enum type.

if( (AdHocGraphicTypeEnum) graphic.Attributes[_adHocGraphicTypeAttributeName]  == AdHocGraphicTypeEnum.UserSketch) {...}

Mike_Quetel
Frequent Contributor

Thanks Jennifer, your suggestion is a good workaround for me.   I'm not used to seeing a dictionary<string,object> that would not take something that ultimately derives from system.object   (enum inherits from valuetype which inherits from object).

0 Kudos
JenniferNery
Esri Regular Contributor

You are correct that object data type in Attributes dictionary imply any user-defined type may be supported as well. This was also possible in v10.x releases at least in the context of Graphics.

But with v100.x, creation of fields (which defines the columns of database table) are limited to types ArcGIS Server support, which means the Attributes (which represent row values) follow this same restriction.