Re: [RavenDB] Storing byte array as a part of the document

156 views
Skip to first unread message

Egor Shamanaev

unread,
Feb 11, 2021, 7:55:03 AM2/11/21
to rav...@googlegroups.com
Hi 

You can convert the byte[] and store it as string

var bytesAsString = Encoding.UTF8.GetString(Data);

On Thu, Feb 11, 2021 at 2:08 PM Arash Sabet <arash...@umplify.com> wrote:
I have a simple object with a byte array as one of its properties. Example:

public class MyObject
{
     public string Id{ get; set; }
     public string Name { get; set; }
     public byte[] Data { get; set; }
}

When trying to store this object, all properties appear in the document but "Data" which appears to be null in RavenDB. What's the right approach to get it saved properly?

--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ravendb/ccbbcea7-46b2-4df0-820a-633056a501e9n%40googlegroups.com.


--
Egor
Developer   /   Hibernating Rhinos LTD
Support:  sup...@ravendb.net
  

Arash Sabet

unread,
Feb 11, 2021, 4:37:57 PM2/11/21
to RavenDB - 2nd generation document database

Raven DB already does that automatically without me having to converting the byte array string. The issue is that when that byte array is read back from the RavenDB and plugging into X509Certificate2(byte[]  rawData  , string password) constructor, that contractor fails after due to the following exception. Is it possible that RavenDB does not store byte arrays properly? If not what's the solution?!

Cannot find the requested object.

   at Internal.Cryptography.Pal.CertificatePal.FromBlobOrFile(Byte[] rawData, String fileName, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)
   at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags)
   at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData, String password)

 

Oren Eini (Ayende Rahien)

unread,
Feb 12, 2021, 4:08:22 PM2/12/21
to ravendb
RavenDB stores byte arrays just fine, here is an example test that shows how:

Can you send us a way to reproduce this issue?




--
Oren Eini
CEO   /   Hibernating Rhinos LTD
Skype:  ayenderahien
Support:  sup...@ravendb.net
  

Oren Eini (Ayende Rahien)

unread,
Feb 12, 2021, 4:08:49 PM2/12/21
to ravendb
As an aside, for large binary data ( and certificate is usually several kb, so might fit), you may want to store the data as an attachment, but that isn't related to storing byte[]

Arash Sabet

unread,
Feb 14, 2021, 7:45:44 AM2/14/21
to rav...@googlegroups.com
I will share a piece of code on Tuesday.

You received this message because you are subscribed to a topic in the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ravendb/AVm0hmbB-jM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ravendb+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ravendb/CAF0G-Zj7uf_yU1MEvXxSUPt0UijEzPtUNgiPaXjbmf4J0X-59g%40mail.gmail.com.

Arash Sabet

unread,
Feb 14, 2021, 9:35:30 AM2/14/21
to rav...@googlegroups.com
We tried attachments but it never worked either! I already shared a private repo with Grisha. I was told by Griash that I will be communicated something this week.

You received this message because you are subscribed to a topic in the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ravendb/AVm0hmbB-jM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ravendb+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ravendb/CAF0G-Zj7uf_yU1MEvXxSUPt0UijEzPtUNgiPaXjbmf4J0X-59g%40mail.gmail.com.

Arash Sabet

unread,
Feb 16, 2021, 7:41:33 AM2/16/21
to RavenDB - 2nd generation document database
@Oren just wondering, does the private repo that I shared with Grisha the other day suffice for investigation?

Oren Eini (Ayende Rahien)

unread,
Feb 17, 2021, 1:16:26 AM2/17/21
to ravendb
The issue was a call to Read() that wasn't in a loop.
Read() is allowed to return partial results (basically, whatever it has in the buffer).
The code assumes that a single Read() call will get the entire data, but that isn't the case. 

Reply all
Reply to author
Forward
0 new messages