【发布时间】:2023-03-21 10:20:01
【问题描述】:
我的代码使用 Castle DynamicProxy 来代理代码调用。在 Intercept(IInvocation invocation) 中,我使用 NewtonSoft 对调用进行 Json 序列化。
Newtonsoft.Json.JsonConvert.SerializeObject(invocation.Method);
在框架中,这会产生一个非常简洁的东西,如下所示:
{
"Name": "FastLoadDataAsJson",
"AssemblyName": "TinyData, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
"ClassName": "Dimension2.Core.Database.TinyData",
"Signature": "Byte[] FastLoadDataAsJson(System.String, System.String, System.String)",
"Signature2": "System.Byte[] FastLoadDataAsJson(System.String, System.String, System.String)",
"MemberType": 8,
"GenericArguments": null
}
在 .Net Core 项目中,相同的序列化调用首先给出此异常:
检测到类型为“System.Reflection.RuntimeModule”的属性“ManifestModule”的自引用循环。路径'Module.Assembly'。'
我可以使用设置 Newtonsoft.Json.ReferenceLoopHandling.Ignore 绕过它
但我返回的 JSON 有 93,000 行长!!!这到底是怎么回事?调用似乎完全不同。除了长度之外,属性也不同,例如没有 Signature 或 Signature2 属性。
框架简洁的 Json 似乎完全适合描述我们需要进行的调用。那么为什么Core如此不同呢?我担心我遗漏了有关 Castle、Core 或两者的重要信息。
【问题讨论】:
标签: .net .net-core json.net castle-dynamicproxy binary-serialization