cant insert type byte[] to database

995 views
Skip to first unread message

itsik_a

unread,
Jun 19, 2011, 9:01:37 AM6/19/11
to mongodb-csharp
I'm writing in C#, I want to insert "byte array" to the db collection,
but getting error:

Specified argument was out of the range of valid values"
"Parameter name: Type: System.Byte not recognized

Why it's not working? did mongoDB dosen't familiar with byte array
type? it's not using the BSON.Binary type?

How can iI tell him to do the conversion to BSON.Binary using
attrbiute and not changing the class??

Robert Stam

unread,
Jun 19, 2011, 10:00:06 AM6/19/11
to mongodb-csharp
Byte array is a supported data type. For example, you could define a
class like:

public class C {
public ObjectId Id;
public byte[] Data;
}

And then use code like this to save an instance of C to the database:

var c = new C { Data = new byte[] { 1, 2, 3 } };
collection.Save(c);

If looking at this sample code doesn't answer your question, please
provide additional information, such as:

- what version of the C# driver are you using
- your class declaration
- the code you wrote that is getting an error
- a stack trace
Reply all
Reply to author
Forward
0 new messages