Memobache provider Protobuf-net does not work in append / set ArraySegment

I am using protobuf-net lib with protobuf-net memcache provider and I am trying to use memcache add function:

var data = new ArraySegment<byte>(Encoding.UTF8.GetBytes("appendedString"));
var result = _memcache.ExecuteStore(StoreMode.Add, key, data);

      

And this throws the exception:

The runtime encountered a fatal error. The error address was at 0x63765a43, on stream 0xd58. Error code: 0xc0000005. This error could be a bug in the CLR, or in an unsafe or unverifiable piece of user code. Common sources of this error include user marshaling errors for COM interop or PInvoke, which can mess up the stack.

I did some debugging and found out when this exception is thrown:

/Meta/RuntimeTypeModel.cs: 692: ((Type MetaType) [key]). Serializer.Write (value, dest);

The value

point here is that the ArraySegment I want to set as a value dest

is ProtoBuf.ProtoWriter.

Is there a way to fix this error or maybe I am doing something wrong. Maybe I just need to store not ArraySegment but just a string and add strings to it?

+1


source to share


1 answer


Heh; to be honest, I've never tested ArraySegment<T>

- despite the intentions of the CLR team, it just isn't used that much. I can reproduce this in a very simple test:

using ProtoBuf;
using System;
[ProtoContract]
class Foo
{
    [ProtoMember(1)]
    public ArraySegment<byte> Data { get; set; }
    static void Main()
    {
        var obj = new Foo { Data = new ArraySegment<byte>(new byte[] { 1, 2, 3 })};
        Serializer.PrepareSerializer<Foo>();
        var clone = Serializer.DeepClone(obj);
    }
}

      



which I will add to the test suite and fix.

Currently I suggest: just save byte[]

... (i.e. don't use ArraySegment<T>

). This will probably be fixed in the next build of protobuf-net.

+2


source







All Articles