Description
DESCRIPTION
There is an issue with the use of atomic operations in the last version of the library.
The problem is that when we increase the log level to Trace
level, the requests begins to fail because it's trying to serialize properties of 'System.Type' type.
We detect that the fail is produced inside the function LogMethodStart
located at TraceLogWriter
class that's called at the beginning of the implemented method inside, and these are the details of the exception:
Message:
Serialization and deserialization of 'System.Type' instances are not supported. Path: $.TargetedFields.Attributes.Property.PropertyType.
StackTrace:
at System.Text.Json.ThrowHelper.ThrowNotSupportedException(WriteStack& state, NotSupportedException ex)
at System.Text.Json.Serialization.JsonConverter`1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.JsonConverter`1.WriteCoreAsObject(Utf8JsonWriter writer, Object value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.JsonSerializer.WriteUsingSerializer[TValue](Utf8JsonWriter writer, TValue& value, JsonTypeInfo jsonTypeInfo)
at System.Text.Json.JsonSerializer.WriteStringUsingSerializer[TValue](TValue& value, JsonTypeInfo jsonTypeInfo)
at System.Text.Json.JsonSerializer.Serialize[TValue](TValue value, JsonSerializerOptions options)
at JsonApiDotNetCore.Middleware.TraceLogWriter`1.SerializeObject(Object value) in C:\Users\rodriguezalberto\repos\JsonApiDotNetCore\src\JsonApiDotNetCore\Middleware\TraceLogWriter.cs:line 140
at JsonApiDotNetCore.Middleware.TraceLogWriter`1.WriteObject(StringBuilder builder, Object value) in C:\Users\rodriguezalberto\repos\JsonApiDotNetCore\src\JsonApiDotNetCore\Middleware\TraceLogWriter.cs:line 116
at JsonApiDotNetCore.Middleware.TraceLogWriter`1.WriteProperty(StringBuilder builder, PropertyInfo property, Object instance) in C:\Users\rodriguezalberto\repos\JsonApiDotNetCore\src\JsonApiDotNetCore\Middleware\TraceLogWriter.cs:line 104
at JsonApiDotNetCore.Middleware.TraceLogWriter`1.WriteProperties(StringBuilder builder, Object propertyContainer) in C:\Users\rodriguezalberto\repos\JsonApiDotNetCore\src\JsonApiDotNetCore\Middleware\TraceLogWriter.cs:line 80
at JsonApiDotNetCore.Middleware.TraceLogWriter`1.FormatMessage(String memberName, Object parameters) in C:\Users\rodriguezalberto\repos\JsonApiDotNetCore\src\JsonApiDotNetCore\Middleware\TraceLogWriter.cs:line 57
at JsonApiDotNetCore.Middleware.TraceLogWriter`1.LogMethodStart(Object parameters, String memberName) in C:\Users\rodriguezalberto\repos\JsonApiDotNetCore\src\JsonApiDotNetCore\Middleware\TraceLogWriter.cs:line 36
at JsonApiDotNetCore.Controllers.BaseJsonApiOperationsController.<PostOperationsAsync>d__7.MoveNext() in C:\Users\rodriguezalberto\repos\JsonApiDotNetCore\src\JsonApiDotNetCore\Controllers\BaseJsonApiOperationsController.cs:line 107
STEPS TO REPRODUCE
- Create an new project with the last version of JsonApiDotNetCore library
- Add a resource and a controller inheriting the base class
BaseJsonApiOperationsController
- Implement the
PostOperationsAsync
method and call to the base method.
Sample project:
https://github.com/arcarrillo/jsonapidotnetcore-trace
Sample call to this project (local execution):
curl --location 'https://localhost:7284/api/atomic' \
--header 'Content-Type: application/vnd.api+json; ext="https://jsonapi.org/ext/atomic"' \
--data '{
"atomic:operations": [
{
"op": "add",
"data": {
"type": "sources",
"attributes": {
"name": "1234"
}
}
}
]
}'
Response:
{
"links": {
"self": "https://localhost:7284/api/atomic"
},
"errors": [
{
"id": "2e365bad-4c41-4f57-84bb-a2e6c6bdc2b1",
"status": "500",
"title": "An unhandled error occurred while processing this request.",
"detail": "Serialization and deserialization of 'System.Type' instances are not supported. Path: $.TargetedFields.Attributes.Property.PropertyType."
}
]
}
EXPECTED BEHAVIOR
The request should be logged
ACTUAL BEHAVIOR
Returns a server error.
VERSIONS USED
- JsonApiDotNetCore version: 5.4.0
- ASP.NET Core version: 6.0.0
- Entity Framework Core version: Not relevant
- Database provider: Not relevant