Yep, I sure can.
The graphic being generated is a poly line. And when I disable adding the M value, and I open the data in ArcMap (ArcMap is on a separate computer, so there's no chance it's interfering) the shape field says "Polyline M" for every item in the attributes table. I took this to mean that it should support having custom measure values.
Regardless, the exception happens (according to my stack trace) in some internal Esri function called InsertRow, which I assume hits the native code because the stack ends there until it re-enters with a method called HandleException (or something like that).
This is pretty important to our application, we desperately need to be able to set custom measure values for the poly lines, or else our data ends up being wrong in some places. As you can imagine, this would greatly annoy our clients to no end.
One other note, you may notice in the code that adds the features back to the table that I'm calling .Wait() for each task. This is necessary for our tasks that build the table data. I don't expect that it would cause this issue (considering it works just fine before adding an M value).
This is the code to create the feature:
private GeodatabaseFeature CreateFeature(DynamicMapFeature feature, ServiceFeatureTable table)
{
GeodatabaseFeature result = table.CreateNew();
foreach (KeyValuePair<string, object> attrib in feature.Attributes)
{
result.Attributes[attrib.Key] = attrib.Value;
}
var points = new List<MapPoint>();
var latLongBuffer = new StringBuilder(32);
MapPointBuilder builder = new MapPointBuilder(_spatialReference);
foreach (DynamicMapPoint point in feature.MapPoints)
{
if (point.IsLatLong)
{
latLongBuffer.Length = 0;
latLongBuffer.Append(point.X);
latLongBuffer.Append(", ");
latLongBuffer.Append(point.Y);
MapPoint mapPoint = ConvertCoordinate.FromDecimalDegrees(latLongBuffer.ToString(), new SpatialReference(26910));
builder.X = mapPoint.X;
builder.Y = mapPoint.Y;
}
else
{
builder = new MapPointBuilder(point.X, point.Y, builder.SpatialReference);
}
// This isn't working. Why?
/*if (point.HasZ)
{
builder.Z = point.Z;
}*/
// This isn't either, but we REALLY need this or else our facility information will be incorrect.
if (point.HasMeasure)
{
builder.M = point.Measure;
}
points.Add(builder.ToGeometry());
}
switch (feature.GeometryType)
{
case FeatureGeometryType.Polygon:
result.Geometry = new Polygon(points, builder.SpatialReference);
break;
case FeatureGeometryType.Polyline:
result.Geometry = new Polyline(points, builder.SpatialReference);
break;
case FeatureGeometryType.Point:
result.Geometry = new Multipoint(points, builder.SpatialReference);
break;
}
return result;
This is the code to add a feature back to the table:
ServiceFeatureTable table = _featureTables[bufferIndex];
// At an earlier preparation stage the feature creation code gets put into the _featureBuffers array
// like so: _featureBuffers[index] = CreateFeature(...);
GeodatabaseFeature[] features = _featureBuffers[bufferIndex];
Task addTask = table.AddAsync(features);
// This is where it fails
addTask.Wait();
Task<FeatureEditResult> syncTask = table.ApplyEditsAsync(false);
syncTask.Wait();
_itemsProcessed = Interlocked.Add(ref _itemsProcessed, syncTask.Result.AddResults.Count(item => item.Success));
var state = new DynamicJobState(string.Format(Resources.DYNMAP_PROG_FEATURE_PROGRESS,
_layerName,
_itemsProcessed,
TotalFeatureCount,
(decimal)ItemsProcessed / TotalFeatureCount),
ItemsProcessed, TotalFeatureCount);
_progressModel.SetJobState(ref state);
return syncTask.Result;