The model binder that processes the request body validates the data using validator defined in 'BodyModelValidator'. The default implementation 'DefaultBodyModelValidator' recursively iterates the object graph. This iteration however fails to properly address the situation when it encounters a property of System.Type type (and potentially other similar types). It considers that type as a composite type recursively processing its sub-properties and fails to get the value of DeclaringMethod property, that throws an exception if accessed on any type that is not a generic argument.
(For search indexing purposes: the exception presents itself as InvalidOperationException with the message "Method may only be called on a Type for which Type.IsGenericParameter is true.")
Current implementation already tests for "simple" types via TypeHelper.IsSimpleType, however this function addresses only primitive types and string, DateTime, Decimal, Guid, DateTimeOffset and TimeSpan.
The quick fix would be to extend that list. However, a better approach would be to expose a mechanism to allow such an extension by a developer: delegate, attribute, virtual method?
For instance, it might be beneficial to skip deep instance inspection in case of types with custom serialization that are treated as opaque.
Comments: Verified. Works for Json media type formatter. Xml formatter throws errors when serializing Type instances though.
(For search indexing purposes: the exception presents itself as InvalidOperationException with the message "Method may only be called on a Type for which Type.IsGenericParameter is true.")
Current implementation already tests for "simple" types via TypeHelper.IsSimpleType, however this function addresses only primitive types and string, DateTime, Decimal, Guid, DateTimeOffset and TimeSpan.
The quick fix would be to extend that list. However, a better approach would be to expose a mechanism to allow such an extension by a developer: delegate, attribute, virtual method?
For instance, it might be beneficial to skip deep instance inspection in case of types with custom serialization that are treated as opaque.
Comments: Verified. Works for Json media type formatter. Xml formatter throws errors when serializing Type instances though.