GeometryEngine.NearestCoordinate(envelope, mapPoint) throws a NotImplementedException.
This is definitely a bug, as the documentation doesn't mention it: GeometryEngine.NearestCoordinate Method
The fix is to convert the Envelope to a Polygon:
private static Polygon EnvelopeToPolygon(Envelope envelope)
{
return new Polygon(new MapPoint[]
{
new MapPoint(envelope.XMin, envelope.YMin, envelope.SpatialReference),
new MapPoint(envelope.XMax, envelope.YMin, envelope.SpatialReference),
new MapPoint(envelope.XMax, envelope.YMax, envelope.SpatialReference),
new MapPoint(envelope.XMin, envelope.YMax, envelope.SpatialReference)
});
}
It really should be implemented, as it's just a few lines of code.