Protobuf-net memcache provider fails on append/set ArraySegment

北战南征 提交于 2020-01-05 10:32:08

问题


I'm using protobuf-net lib with protobuf-net memcache provider and I'm trying to use memcache append function:

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

And it throws exception:

The runtime has encountered a fatal error. The address of the error was at 0x63765a43, on thread 0xd58. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.

I've done some debug and find out place when that exception is raised:

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

Here value is that ArraySegment which I want to set as value and dest is ProtoBuf.ProtoWriter.

Is there any way to fix that error or, maybe, I'm doing something wrong. Maybe I just simply need to store not an ArraySegment, but just string and append strings to it too?


回答1:


Heh; in all honesty I've never tested ArraySegment<T> - despite the intentions of the CLR team, it simply isn't used all 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.

For now, may I suggest: just store the byte[]... (i.e. don't use ArraySegment<T>). This will probably be fixed in the next build of protobuf-net.



来源:https://stackoverflow.com/questions/16838287/protobuf-net-memcache-provider-fails-on-append-set-arraysegment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!