Attachment problem in Unity


#1

Hi,

I have a problem with attachment replication in Unity.
Sometimes when I create a new document with an attachment the document is synchronized together with the attachment but the document can’t find the attachment, that is the GetAttcahment method returns null, but the attachment is in the databse folder.
Then I made some changes on the same document, the replication gets triggered and then the document can find the attachment.
What could be the problem?

Thanks


#2

Could you describe this in more detail as a series of steps, or even better as pseudocode or C# code?


#3

First I create a document as in the example on the couchbase site then save the document,
after that I create a new revision of the document and add the attachment to that revision and then save the new revision and the again I create a new revision and modify some properies. For replication I am using the push and pull replicator.
This is the code for retrieveing the attachment

var revision = _database.GetDocument (scene.Id).GetRevision( scene.RevisionId ); var attachment = revision.GetAttachment ("preview");

And whe replicating the document to another device the attachment is sometimes null but the attachment is in the databse folder.

If the attachment is null, I am updating the document on the original device, that is,
I create a new revision, update the properties and save the new revision and then again I create a new revision add the attachment (it is the same as the previous one) and save the revision with the attachment.
The updated document gets replicated on the other device and the I can access the attachment.


#4

Hi,

I figured what was the problem.
I was using the Properties of the document instead of the UserProperties and the attachment got lost.

Thanks


#5

No you don’t have to do that. By the way did you build the library yourself or use the (very old) prebuilt one?


#6

I am using the prebuilt library.
Should I compile the newest version of couchbase lite for unity?

There is another strange thing that happens with attachments.
When I update the document until the application quits the attachment is not accessible,
concretely the content stream is not accessible, it throws

NullReferenceException: Object reference not set to an instance of an object Couchbase.Lite.StreamExtensions.Reset (System.IO.Stream stream) (at /Users/borrrden/Development/couchbase-lite-net/src/Couchbase.Lite.Shared/Extensions/StreamExtensions.cs:58) Couchbase.Lite.Attachment.get_ContentStream () (at /Users/borrrden/Development/couchbase-lite-net/src/Couchbase.Lite.Shared/Attachment.cs:232)

but after I restart the application I can normally access the content stream.
Also I can access the content stream of the parent revision if the content stream of the current revision is not aviable.


#7

I’d recommend building the release/unity-ga branch. The state of the library has been in a lot of flux due to problems with IL2CPP and so I didn’t make regular builds of it but a release will be coming in the near future. It will be based on the branch I mentioned above.


#8

I built the project and replaced all the dll’s but the problem with the attachment is still there.


#9

In that case please file an issue on the repo with concise reproduction steps and I will take a look at it.