Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Yoshifumi Kawai
    @neuecc
    Hello, welcome to ask any question! Let's talk about the serialization.
    Mariano
    @marianogenovese
    hi!, i have looking your serialization lib and i have a question. In case of dynamic generated types with reflection emit is your lib appropriate for this case?
    Yoshifumi Kawai
    @neuecc
    @marianogenovese Yes, it can serialize. I checked it.
    // craete ZeroFormattable Type dynamically
    var assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("TestTestTest"), AssemblyBuilderAccess.Run);
    var moduleBuilder = assemblyBuilder.DefineDynamicModule("TestModule");
    var typeBuilder = moduleBuilder.DefineType("NewDynamicType", TypeAttributes.Public);
    typeBuilder.SetCustomAttribute(new CustomAttributeBuilder(typeof(ZeroFormattableAttribute).GetConstructor(Type.EmptyTypes), new object[0]));
    
    var field = typeBuilder.DefineField("backingField", typeof(int), FieldAttributes.Private);
    var prop = typeBuilder.DefineProperty("MyProperty", PropertyAttributes.None, typeof(int), Type.EmptyTypes);
    prop.SetCustomAttribute(new CustomAttributeBuilder(typeof(IndexAttribute).GetConstructor(new[] { typeof(int) }), new[] { (object)0 }));
    {
        var getProp = typeBuilder.DefineMethod("get_MyProperty", MethodAttributes.Public | MethodAttributes.Virtual, typeof(int), Type.EmptyTypes);
        var il = getProp.GetILGenerator();
        il.Emit(OpCodes.Ldarg_0);
        il.Emit(OpCodes.Ldfld, field);
        il.Emit(OpCodes.Ret);
        prop.SetGetMethod(getProp);
    }
    {
        var setProp = typeBuilder.DefineMethod("set_MyProperty", MethodAttributes.Public | MethodAttributes.Virtual, null, new[] { typeof(int) });
        var il = setProp.GetILGenerator();
        il.Emit(OpCodes.Ldarg_0);
        il.Emit(OpCodes.Ldarg_1);
        il.Emit(OpCodes.Stfld, field);
        il.Emit(OpCodes.Ret);
        prop.SetSetMethod(setProp);
    }
    
    var dynamicType = typeBuilder.CreateType();
    
    dynamic t = Activator.CreateInstance(dynamicType);
    t.MyProperty = 1000;
    
    // can serialize dynamic type.
    var serializedBytes = ZeroFormatterSerializer.NonGeneric.Serialize(dynamicType, t);
    
    dynamic deserializedInstance = ZeroFormatterSerializer.NonGeneric.Deserialize(dynamicType, serializedBytes);
    
    Console.WriteLine(deserializedInstance.MyProperty); // 1000
    Mariano
    @marianogenovese
    oh thanks for your response! i will try to use your lib in my app :smile:
    Lan
    @crazy6995
    Hi there~
    Riccardo Boccia
    @Rik_boccia_twitter
    @neuecc
    Hi,
    I have a problem with zeroformatter, when I try to deserialize a class that inherits from a List <T>, it goes in exception saying that it can not deserialize the Capacity property of List.
    Is it normal that it do not work or I'm doing something wrong?
    codingadventures
    @codingadventures
    Hi Yoshifumi, I wonder if it's possible to use ZeroFormatter without having to use metadata attributes on custom types (like ZeroFormattable, Index(n) etc) thanks!
    Enzx
    @Enzx
    Hi there,
    Is there any way to use text serialization beside of binary format? (I want to use text for debugging)
    kchennappagarizc
    @kchennappagarizc
    hi @neuecc ,
    I am blocked with an issue with ZeroFormatter, getting below exception when serializing an object
    System.InvalidProgramException: Common Language Runtime detected an invalid program.
    at ZeroFormatter.DynamicObjectSegments.ZeroFormatter_Formatters_DefaultResolver.Colibrium.Common.Ontology.Rating.Factors.RateFactor$Formatter.Serialize(Byte[]& , Int32 , RateFactor )
    at ZeroFormatter.Formatters.CollectionFormatter3.Serialize(Byte[]& bytes, Int32 offset, TCollection value) at ZeroFormatter.DynamicObjectSegments.ZeroFormatter_Formatters_DefaultResolver.Colibrium.Common.Ontology.Rating.RateClass$Formatter.Serialize(Byte[]& , Int32 , RateClass ) at ZeroFormatter.Formatters.CollectionFormatter3.Serialize(Byte[]& bytes, Int32 offset, TCollection value)
    at ZeroFormatter.DynamicObjectSegments.ZeroFormatter_Formatters_DefaultResolver.Colibrium.Common.Ontology.Rating.PackagePlan$Formatter.Serialize(Byte[]& , Int32 , PackagePlan )
    at ZeroFormatter.Formatters.CollectionFormatter3.Serialize(Byte[]& bytes, Int32 offset, TCollection value) at ZeroFormatter.DynamicObjectSegments.ZeroFormatter_Formatters_DefaultResolver.Colibrium.Common.Ontology.Rating.Package$Formatter.Serialize(Byte[]& , Int32 , Package ) at ZeroFormatter.Formatters.CollectionFormatter3.Serialize(Byte[]& bytes, Int32 offset, TCollection value)
    at ZeroFormatter.DynamicObjectSegments.ZeroFormatter_Formatters_DefaultResolver.Colibrium.Common.Ontology.Rating.PackageGroup$Formatter.Serialize(Byte[]& , Int32 , PackageGroup )
    at ZeroFormatter.Formatters.CollectionFormatter3.Serialize(Byte[]& bytes, Int32 offset, TCollection value) at ZeroFormatter.DynamicObjectSegments.ZeroFormatter_Formatters_DefaultResolver.Colibrium.Common.Ontology.Rating.Group.GroupRatingResults$Formatter.Serialize(Byte[]& , Int32 , GroupRatingResults ) at ZeroFormatter.ZeroFormatterSerializer.CustomSerializer1.SerializeT
    kchennappagarizc
    @kchennappagarizc
    that particular class is decorated with union
    kchennappagarizc
    @kchennappagarizc
    this issue is solved when we change app pool from 64 bit to 32 bit... But we can't go with this solution