Comments (4)
One thing worth to mention, if I remove the relationship between "IEntityNameAndId" and "NameAndIdBase", then the serialization of "Property" works. Don't know why. Any idea?
from aqlaserializer.
This is the unit test code to replicate the issue:
using AqlaSerializer;
using System;
using System.Diagnostics;
using System.IO;
using Xunit;
public class UnitTest5
{
private void SetupModel()
{
var metaType2 = AqlaSerializer.Meta.RuntimeTypeModel.Default.Add(typeof(Property), false);
metaType2.DefaultFormat = AqlaSerializer.ValueFormat.Reference;
metaType2.UseConstructor = false;
metaType2.IgnoreListHandling = true;
var metaType3 = AqlaSerializer.Meta.RuntimeTypeModel.Default.Add(typeof(IEntityNameAndId), false);
metaType3.DefaultFormat = AqlaSerializer.ValueFormat.Reference;
metaType3.UseConstructor = false;
metaType3.IgnoreListHandling = true;
var metaType4 = AqlaSerializer.Meta.RuntimeTypeModel.Default.Add(typeof(INameAndId), false);
metaType4.DefaultFormat = AqlaSerializer.ValueFormat.Reference;
metaType4.UseConstructor = false;
metaType4.IgnoreListHandling = true;
AqlaSerializer.Meta.MetaType metaType5 = AqlaSerializer.Meta.RuntimeTypeModel.Default[typeof(IEntityNameAndId)];
metaType5.AddSubType(1, typeof(INameAndId));
AqlaSerializer.Meta.MetaType metaType6 = AqlaSerializer.Meta.RuntimeTypeModel.Default[typeof(Property)];
var metaField1 = metaType6.AddField(1, "_owner");
metaField1.SetSettings(x => { x.V.Format = AqlaSerializer.ValueFormat.Reference; });
metaField1.SetSettings(x => x.V.WriteAsDynamicType = true, 0);
var metaType7 = AqlaSerializer.Meta.RuntimeTypeModel.Default.Add(typeof(NameAndIdBase), false);
metaType7.DefaultFormat = AqlaSerializer.ValueFormat.Reference;
metaType7.UseConstructor = false;
metaType7.IgnoreListHandling = true;
AqlaSerializer.Meta.MetaType metaType8 = AqlaSerializer.Meta.RuntimeTypeModel.Default[typeof(NameAndIdBase)];
var metaField2 = metaType8.AddField(1, "_id");
metaField2.SetSettings(x => { x.V.Format = AqlaSerializer.ValueFormat.Compact; });
var metaField3 = metaType8.AddField(2, "_name");
metaField3.SetSettings(x => { x.V.Format = AqlaSerializer.ValueFormat.Compact; });
AqlaSerializer.Meta.MetaType metaType10 = AqlaSerializer.Meta.RuntimeTypeModel.Default[typeof(IEntityNameAndId)];
metaType10.AddSubType(2, typeof(NameAndIdBase));
var metaType11 = AqlaSerializer.Meta.RuntimeTypeModel.Default.Add(typeof(NameAndId), false);
metaType11.DefaultFormat = AqlaSerializer.ValueFormat.Reference;
metaType11.UseConstructor = false;
metaType11.IgnoreListHandling = true;
AqlaSerializer.Meta.MetaType metaType12 = AqlaSerializer.Meta.RuntimeTypeModel.Default[typeof(NameAndIdBase)];
metaType12.AddSubType(3, typeof(NameAndId));
}
[Fact]
public void TestSerialization()
{
SetupModel();
var property = new Property();
property.Owner = new NameAndId(101, "test");
var stream = new MemoryStream();
try
{
Serializer.Serialize(stream, property);
}
catch (Exception e)
{
Debug.WriteLine($"Failed to serialize property: {e.Message}");
throw;
}
}
}
public class Property
{
private INameAndId _owner;
public INameAndId Owner { get => _owner; set => _owner = value; }
}
public sealed class NameAndId : NameAndIdBase, INameAndId
{
public NameAndId(int id, string name)
: base(id, name)
{
}
}
public class NameAndIdBase : IEntityNameAndId
{
private readonly string _name = string.Empty;
private readonly int _id;
public NameAndIdBase(int id, string name)
{
_id = id;
_name = name;
}
public int Id => _id;
public string Name => _name;
}
public interface INameAndId : IEntityNameAndId
{
}
public interface IEntityNameAndId
{
int Id { get; }
string Name { get; }
}
from aqlaserializer.
If we remove the following two lines from the "SetupModel" method, the test passes. I don't know why.
AqlaSerializer.Meta.MetaType metaType10 = AqlaSerializer.Meta.RuntimeTypeModel.Default[typeof(IEntityNameAndId)];
metaType10.AddSubType(2, typeof(NameAndIdBase));
from aqlaserializer.
Found a workaround on our side.
from aqlaserializer.
Related Issues (20)
- Non-public member cannot be used with full dll compilation HOT 12
- AqlaSerializer.ProtoException: Trap count > 1, will be mismatched with next NoteObject HOT 15
- Dynamic type is not a contract-type
- Un-defined enum values HOT 1
- Unexpected sub-type HOT 4
- Wrong group was ended
- Recursion depth exceeded safe limit HOT 2
- "Unable to determine member" when running obfuscated code HOT 1
- A deferred key does not have a value yet (NoteObject call missed?) HOT 10
- How to unregister or re-register a type? HOT 6
- Can you please publish the latest code?
- Failed to clone a dictionary with enum value
- Unable to Serialize a string object dictionary containing a string array as object
- Is Aqla's metadata inspection thread-safe? HOT 2
- Is there a way to re-compile the runtime type model as a dll? HOT 2
- Can we reformat the source code? HOT 1
- Reference tracking error message only for release build but not for debug build
- When a SortedDictionary is serialized, does Aqla keep the "Comparer" of it? HOT 1
- Does the order of adding types to type model matter? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aqlaserializer.