Skip to content

Conversation

@eNeRGy164
Copy link
Member

@eNeRGy164 eNeRGy164 commented Jun 25, 2025

The ReturnType property on MethodDescription was causing System.ArgumentException: 'Property set method not found.' during JSON deserialization with System.Text.Json.

Problem

When deserializing JSON containing method definitions with explicit return types:

[{
  "FullName": "Example.Class",
  "Methods": [{
    "Name": "GetAllAsync",
    "ReturnType": "System.Threading.Tasks.Task<Microsoft.AspNetCore.Mvc.IActionResult>"
  }]
}]

The deserialization would fail because:

  1. The ReturnType property was read-only (getter only)
  2. The custom default value handling logic in JsonDefaults.cs attempted to set values on properties with [DefaultValue] attributes
  3. This caused a reflection error when trying to call the non-existent setter

Solution

Minimal changes applied:

Fixes an issue with JSON deserialization of the ReturnType property by making it internally settable and refining how default values are applied.

  1. Updated JsonDefaults logic to skip non-writable properties, preventing reflection errors

Verification

  • ✅ JSON with explicit ReturnType values now deserialize correctly
  • ✅ JSON without ReturnType still defaults to "void" as expected
  • ✅ All existing tests continue to pass (253 tests)
  • ✅ Added comprehensive unit tests for both scenarios

The fix ensures backward compatibility while enabling proper deserialization of method return type information from JSON.

Fixes #38.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

* Fix ReturnType property deserialization by using CanWrite check

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: eNeRGy164 <10671831+eNeRGy164@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 25, 2025 15:04
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ensures the ReturnType property on MethodDescription can be populated during System.Text.Json deserialization and prevents reflection errors when applying default values.

  • Made ReturnType internally settable so JSON can write to it.
  • Updated SetDefaultValues to skip properties that have no setter.
  • Added tests to verify both explicit and missing ReturnType scenarios.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
tests/DendroDocs.Shared.Tests/Serialization/TextJsonDeserializationTests.cs Added tests for deserializing methods with and without ReturnType.
src/DendroDocs.Shared/Json/JsonDefaults.cs Guarded default-value assignment to skip properties without setters.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 15880032934

Details

  • 3 of 3 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 96.09%

Totals Coverage Status
Change from base Build 15452699960: 0.02%
Covered Lines: 566
Relevant Lines: 571

💛 - Coveralls

@eNeRGy164 eNeRGy164 merged commit 7bd1772 into dendrodocs:main Jun 25, 2025
2 checks passed
@eNeRGy164 eNeRGy164 added the bug Something isn't working label Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ReturnValue on MethodDescription can't be set on System.Text.Json deserialization

2 participants