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.
'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)
--- 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 GeocortexApp.WinForms.Runtime.RuntimeReplicaProvider.<AddAttachment>d__18.MoveNext() in C:\svn\GeocortexApp\_Trunk\GeocortexApp.WinForms\Runtime\RuntimeReplicaProvider.cs:line 560
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
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?
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.