AqlaSolutions / AqlaSerializer

Binary serializer with full .NET support!
http://www.aqla.net
Other
16 stars 3 forks source link

Non-public member cannot be used with full dll compilation #39

Closed inethui closed 2 years ago

inethui commented 2 years ago

I got the error in our tests: Non-public member cannot be used with full dll compilation

I didn't call the "Compile" method, how could the "full dll compilation" being triggered? Any idea what could be wrong? The same code works fine with Protobuf-net 2.4.6.

Thanks

This is the call stack:

AqlaSerializer.Compiler.CompilerContext.CheckAccessibility(member)
AqlaSerializer.Compiler.CompilerContext.LoadValue(field)
AqlaSerializer.Serializers.FieldDecorator.EmitWrite(ctx, valueFrom)
AqlaSerializer.Serializers.ProtoDecoratorBase.AqlaSerializer.Serializers.IProtoSerializer.EmitWrite(ctx, valueFrom)
AqlaSerializer.Serializers.TypeSerializer.AqlaSerializer.Serializers.IProtoSerializer.EmitWrite(ctx, valueFrom)
AqlaSerializer.Serializers.CompiledSerializer.AqlaSerializer.Serializers.IProtoSerializer.EmitWrite(ctx, valueFrom)
AqlaSerializer.Meta.RuntimeTypeModel.WriteSerializers.AnonymousMethod__0(pair)
AqlaSerializer.Meta.RuntimeTypeModel.WriteSerializers.AnonymousMethod__1()
AqlaSerializer.Meta.RuntimeTypeModel.WriteSerializers(options, assemblyName, type, hasInheritance, methodPairs, ilVersion)
AqlaSerializer.Meta.RuntimeTypeModel.Compile(options)
AqlaSerializer.Meta.RuntimeTypeModel.Compile(name, path)
AqlaSerializer.Meta.RuntimeTypeModel.CompileForCheckAndValidate(rtm)
AqlaSerializer.Meta.RuntimeTypeModel.GetInvertedVersionForCheckCompiledVsNot(key, metaType)
AqlaSerializer.Meta.RuntimeTypeModel.Serialize(key, value, dest, isRoot)
AqlaSerializer.Meta.TypeModel.SerializeCore(writer, value, isRoot)
AqlaSerializer.Meta.TypeModel.Serialize(dest, value, context)
AqlaSerializer.Meta.TypeModel.Serialize(dest, value)
AqlaSolutions commented 2 years ago

Please use Release configuration of AqlaSerializer

inethui commented 2 years ago

Not sure what you mean "Release configuration". Can you be more specific?

AqlaSolutions commented 2 years ago

AqlaSerializer in debug build performs additional checks to ensure that serialization with compilation and without produces same bytes.

inethui commented 2 years ago

Does Aqla support read-only properties? I found a situation which is supported by Protobuf-net but not by Aqla. The protobuf-net test "CloneReadOnlyPropertyWithProtobuf" in the following code works but the aqla test "CloneReadOnlyPropertyWithAqla" fails with error message:

    System.InvalidOperationException : System.String Text: Cannot apply changes to property PrototypeTests.ReadOnlyPropertyTests+WithReadOnlyProperty.Text
---- System.InvalidOperationException : Cannot apply changes to property PrototypeTests.ReadOnlyPropertyTests+WithReadOnlyProperty.Text
    public class ReadOnlyPropertyTests
    {
        [ProtoContract]
        private class WithReadOnlyProperty
        {
            public WithReadOnlyProperty()
            {
            }

            public WithReadOnlyProperty(string text)
            {
                Text = text;
            }

            [ProtoMember(1)]
            public string Text { get; }
        }

        [Fact]
        public void CloneReadOnlyPropertyWithProtobuf()
        {
            var obj = new WithReadOnlyProperty("test");
            var clone = ProtoBuf.Serializer.DeepClone(obj);

            Assert.Equal(obj.Text, clone.Text);
        }

        [Fact]
        public void CloneReadOnlyPropertyWithAqla()
        {
            var obj = new WithReadOnlyProperty("test");
            var clone = AqlaSerializer.Serializer.DeepClone(obj);

            Assert.Equal(obj.Text, clone.Text);
        }
    }
AqlaSolutions commented 2 years ago

Please set method MetaType.AddField parameter useBackingFieldIsNoSetter to true. protobuf-net removed this parameter.

inethui commented 2 years ago

We use protobuf attributes in this case. How to set useBackingFieldIsNoSetter? Is there a global setting for this?

AqlaSolutions commented 2 years ago

No, you can only set it with MetaType.AddField. I also removed this parameter in develop branch.

inethui commented 2 years ago

I tried the develop branch, the problem is still there. Are you able to run the test code I posted?

BTW I'm using the debug build as I'm having trouble to create a release build of Aqla. Is this a problem?

inethui commented 2 years ago

When I tried to run a release build (with VS 2022 community edition), I got the following error: Error MSB3644 The reference assemblies for .NETFramework,Version=v4.0 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks I went to "https://aka.ms/msbuild/developerpacks" but the Developer Pack 4.0 isn't available anymore. Any idea how to get around this? Can you add the support of .NET Framework 4.8?

AqlaSolutions commented 2 years ago

You have to either use VS2019 or remove not supported target frameworks in the csproj. You can also continue running DEBUG configuration but set RuntimeTypeModel.SkipCompiledVsNotCheck = true.

AqlaSolutions commented 2 years ago

Set ((AutoAddStrategy)model.AutoAddStrategy).UseBackingFieldsIfNoSetter = true;

inethui commented 2 years ago

This works, thank you!