-
-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix crash on operations requests when trace logging is turned on #1396
Conversation
e006c3d
to
3185bec
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #1396 +/- ##
==========================================
+ Coverage 90.65% 90.79% +0.13%
==========================================
Files 342 342
Lines 11047 11069 +22
Branches 1817 1811 -6
==========================================
+ Hits 10015 10050 +35
+ Misses 679 667 -12
+ Partials 353 352 -1 ☔ View full report in Codecov by Sentry. |
3185bec
to
ce07172
Compare
hi @bkoelman, Message StackTrace:
It seems that the error comes from trying to convert this serializer to a converter working with derived classes.
If you like the solution, you could adopt it. If not, I'll be waiting for the next commit, 🙂
|
@arcarrillo Thanks for trying this out. The issue you're experiencing went unnoticed because we reference System.Text.Json v7 from tests for unrelated reasons, which apparently is more flexible. I've integrated your fix and addressed another issue related to resource inheritance. |
Thanks a lot @bkoelman. Now it's working perfect!!! |
There are several ways to prevent the crash from happening.
The problem is that the parameter of the operations action method includes contextual information such as
IJsonApiRequest
andITargettedFields
, which reference elements from the resource graph, which contain members of typeType
andPropertyInfo
. The JSON serializer chokes on these, throwing aNotSupportedException
.The easiest fix would be to catch these errors and omit the parameter from the logs. Or add several
[JsonIgnore]
annotations in the resource graph.But we can do better by adding custom JsonConverters that prevent drilling down into reflection members, and instead write only the relevant information. For example, when writing
ResourceType
only itsPublicName
is relevant in the logs. Furthermore we need to "help" the serializer a bit when it sees an array ofIIdentifiable
to instead use the runtime-type for its elements, so it serializes all properties of, for example, Product, instead of only its ID.Fixes #1397.
QUALITY CHECKLIST