Skip to content

fix: Restore runtime compatibility with System.Text.Json 6.0 #2904

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

Merged
merged 4 commits into from
May 19, 2025

Conversation

leonardo-fernandes
Copy link
Contributor

A few clients started reporting a MethodNotFound since v20.1.2, related to ValueIsEscaped property. Turned out these clients were using System.Text.Json 6.0 at runtime, due to an older dependency.
The MethodNotFound is thrown when Read is invoked (as it has to resolve all method references in its body before executing), so it wasn't caught by the try/catch in Read itself.
Moving the ValueIsEscaped call to another method, causes the MethodNotFound to be thrown only when that method is invoked, and is now caught by the try/catch. IMO this fixes compatibility with older versions of the dll without disrupting the codebase.

@leonardo-fernandes leonardo-fernandes changed the title Restore runtime compatibility with System.Text.Json 6.0 fix: Restore runtime compatibility with System.Text.Json 6.0 Apr 27, 2025
@jnyrup
Copy link
Contributor

jnyrup commented Apr 27, 2025

Just throwing in an alternative, not sure if it's better.

Wrap the call to ValueIsEscaped in a method.
If the JIT inlines the method, it might need to be annotated with NoInlining.

@leonardo-fernandes
Copy link
Contributor Author

leonardo-fernandes commented Apr 27, 2025

Wrap the call to ValueIsEscaped in a method.

I didn't write it that way because I thought it would be more artificial in terms of code readability. But I'm open to any changes.

If the JIT inlines the method, it might need to be annotated with NoInlining.

I believe it wouldn't be inlined on the first invocation, which is when the MethodNotFound is thrown. So I don't think the annotation is strictly needed.

@leonardo-fernandes
Copy link
Contributor Author

@kblok and @jnyrup what is your opinion on this PR? Any questions or suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy