I have code that uses Castle DynamicProxy to proxy code invocation. In Intercept(IInvocation invocation), I use NewtonSoft to Json serialize the invocation.
Newtonsoft.Json.JsonConvert.SerializeObject(invocation.Method);
In Framework this yields a pretty succinct thing that looks like this:
{
"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
}
In a .Net Core project the same serialization call first gives this exception:
Self referencing loop detected for property 'ManifestModule' with type 'System.Reflection.RuntimeModule'. Path 'Module.Assembly'.'
I can get around it using the setting Newtonsoft.Json.ReferenceLoopHandling.Ignore
But JSON I get back is 93,000 lines long!!! What on earth is going on? It seems the invocation is drastically different. Besides just the length, the properties are different, for example there is no a Signature nor Signature2 property.
The Framework succinct Json seems entirely appropriate to describe the invocation we need to make. So why is Core so different? I worry that I am missing something important about Castle, Core, or both.
The
IInvocation.Methodproperty is of typeSystem.Reflection.MethodInfo, JSON serializing that object with JSON.NET is unrelated to Castle Core.Looking at .NET Framework's serialization functionality shows where JSON.NET is getting those from. .NET Core does not support binary serialization and so JSON.NET would be using its usual serialization of public properties, causing it to run into cyclic references.
(https://referencesource.microsoft.com/#mscorlib/system/reflection/memberinfoserializationholder.cs)