Closed MaxHorstmann closed 5 years ago
Btw, Newtonsoft serializes the Func
property like this:
{
"Bar": {
"Method": {
"Name": "<Main>b__0_0",
"AssemblyName": "ConsoleApp8, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
"ClassName": "MyConsoleApp.Program+<>c",
"Signature": "System.String <Main>b__0_0(System.String)",
"Signature2": "System.String <Main>b__0_0(System.String)",
"MemberType": 8,
"GenericArguments": null
},
"Target": {}
}
}
JIL (when it doesn't throw) just produces this:
{"Bar":{}}
This is by design, as a consequence of setting the IncludeInherited
results in Jil trying to serialize the Delegate
-provided members of bar, which ultimately includes a Type
whose GenericParameterPosition
property throws and exception upon access.
Basically, Jil doesn't special case Type
or Delegate
- and Type
's parameters are not safe to access arbitrarily. I'd suggest using a different Options
, or adding [IgnoreDataMember]
to your delegate members.
Serializing a
Func
member works fine withoutOptions.ISO8601PrettyPrintIncludeInherited
, but throws anInvalidOperationException
withOptions.ISO8601PrettyPrintIncludeInherited
: