AppFabric缓存 - 什么是对象序列化的反序列化和要求? [英] AppFabric Caching - What are its serialization and deserialization requirements for an object?

查看:285
本文介绍了AppFabric缓存 - 什么是对象序列化的反序列化和要求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:当缓存一个类的实例,并立即得到它背出来缓存,我得到的对象返回(其不为空),但它的所有属性/字段为空或默认值

Problem: When caching an instance of a class and immediately getting it back out of cache, i get the object back (its not null), but all of its properties / fields are null or defaults.

    _cacheHelper.PutInCache("testModuleControlInfoOne", mci);
    //mci has populated fields

    var mciFromCacheOne = _cacheHelper.GetFromCache("testModuleControlInfoOne");
    //mciFromCacheOne now has null or default fields



所以我怀疑的方式,对象结构性的问题和AppFabric的不正确序列化对象的某些原因。

So I suspect the way the object is structured is the problem and AppFabric is not serializing the object properly for some reason.

然而,当我用下面的序列化方法,我得到的对象回来了所有属性/领域正如之前的系列化他们

When I use the following Serialization method however, I get the object back with all properties / fields as they were prior to serialization.

    public T SerializeThenDeserialize<T>(T o) where T : class
    {
            BinaryFormatter bf = new BinaryFormatter();

            using (MemoryStream ms = new MemoryStream())
            {
                bf.Serialize(ms, o);

                ms.Position = 0;

                return (T)bf.Deserialize(ms);
            }
    }



如何对象序列化和反序列化正确使用二进制格式化而不是通过缓存做同样的事情?

How can an object serialize and deserialize properly using the binary formatter and not do exactly the same thing via caching?

有没有人遇到过这样或有没有人对一般怎么看出来的任何建议或提示吗?

Has anyone encountered this or does anyone have any suggestions or tips on generally what to look out for?

推荐答案

确定找到了。

实施的IXmlSerializable所以AppFabric的对象使用的,而不是常规序列化。

The object implemented IXmlSerializable so AppFabric used that instead of the regular serialization.

通过一个XmlSerializer(而不是一个BinaryFormatter的)给出了相同的空字段,因为我是经历。

Running it through an XmlSerializer (instead of a BinaryFormatter) gives the same null fields as I was experiencing.

看来IXmlSerializable的实现有问题。

It seems the IXmlSerializable implementation has issues.

这篇关于AppFabric缓存 - 什么是对象序列化的反序列化和要求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆