GeodatabaseFeatureTable.AddAttachmentAsync() Is Failing if Attachments Not Synced

3129
5
12-02-2015 12:11 PM
JeffSiemens
New Contributor II

I'm getting a null reference exception on GeodatabaseFeatureTable.AddAttachmentAsync().

Here's a code snippet.

            var table = _gdb.GetFeatureTableById(layerId);

            var feature = (GeodatabaseFeature)await table.QueryAsync(featureId);

            var canAddAttachment = table.CanAddAttachment(feature); // Returns true

            var hasAttachments = table.HasAttachments; // Returns true

            var result = await table.AddAttachmentAsync(featureId, options.Data, options.FileName, options.ContentType); // Null reference exception

The null reference exception is happening inside AddAttachmentAsync(). Interestingly, both CanAddAttachment() and HasAttachments both return true even if the table does not have any attachments synced.

If attachments are included when the geodatabase is generated, then all is well.

But... it seems like users should not be forced to take attachments offline in order to add new attachments. There could be *a lot* of attachment data, and therefore this could really bloat download size and storage space requirements.

In any event, if this is not possible (though it would be nice if it was), a better error message other than a null reference exception would be nice.

0 Kudos
5 Replies
dotMorten_esri
Esri Notable Contributor

I assume 'options' isn't null? Could you share the full stacktrace?

0 Kudos
JeffSiemens
New Contributor II

'options' is not null.

Here is the stack trace:

System.NullReferenceException: Object reference not set to an instance of an object.

   at RuntimeCoreNet.BinaryReaderExtensions.ReadIntPtr(BinaryReader r)

   at RuntimeCoreNet.CoreFeatureSource.AddAttachment(Int64 featureID, CoreAttachment coreAttachment)

   at Esri.ArcGISRuntime.Data.ArcGISFeatureTable.<AddAttachmentAsync>d__23.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

   at GeocortexApp.WinForms.Runtime.RuntimeReplicaProvider.<AddAttachment>d__18.MoveNext() in C:\svn\GeocortexApp\_Trunk\GeocortexApp.WinForms\Runtime\RuntimeReplicaProvider.cs:line 560

0 Kudos
ArneDahlman
New Contributor III

Hi

I had the same problem!

After setting the parmater ReturnAttachments to true in GenerateGeodatabaseParameters it seems to work.

var gdbParams = new GenerateGeodatabaseParameters(layerHandler.LayerIds, sverigeExtent)

{

    OutSpatialReference = sverigeExtent.SpatialReference,

    SyncModel = SyncModel.PerLayer,

    LayerQueries = layerQueryDictionary,

    ReturnAttachments = true

};

/Arne

0 Kudos
JeffSiemens
New Contributor II

Right, but having to download all attachments in order to add new attachments is crazy. This could lead to massively bloated downloads, or out-right failures if the replica is too big for ArcGIS Server to generate. Hopefully this will be addressed with the Quartz release?

0 Kudos
ArneDahlman
New Contributor III

If you dont need the whole layer you can add filter statments to the checkout paramters.
If you need the whole layer, but not the images, and you still want to be able to add new images...
Then I think you will have to do this in a different way or hope for new functionality in the future.
Maybe you can store the new images with the featureids separately and handle this at checkin time.

0 Kudos