modelcontextprotocol / modelcontextprotocol/csharp-sdk
Allow JsonSerializerOptions without TypeInfoResolver
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 4.5k
- Forks
- 814
- Avg merge
- 9d 19h
- Merged PRs (30d)
- 4
Description
I have JsonSerializerOptions which only adds some converters and set the naming policy. I don't have a source generated JsonSerializerContext and therefore no TypeInfoResolver.
When passing these options to a WithTools function, I get the exception:
JsonSerializerOptions instance must specify a TypeInfoResolver setting before being marked as read-only.
I understand that making these options read only is a good thing, but I don't understand enough about the difference to the overload of MakeReadOnly(populateMissingResolver) on the options.
I can set TypeInfoResolver = new DefaultJsonTypeInfoResolver() on my options, but that seems a bit weird.
To Reproduce
Steps to reproduce the behavior:
- Pass a
new System.Text.Json.JsonSerializerOptions()object to one of theWithToolsfunctions.
Expected behavior
No exception should be thrown.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the WithTools implementation mentioned in the issue and trace how the supplied JsonSerializerOptions are made read-only. Reproduce the behavior with a new System.Text.Json.JsonSerializerOptions that only adds converters and a naming policy; done means passing it to WithTools throws no exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100