Invoke conversion methods that take an IFormatProvider or optional parameters - #96
Merged
Merged
Conversation
…rameters [patch] FindStringConversionMethod accepted any FromString/Parse/Create/Convert whose first parameter is a string, but Read always invoked it with one argument, so types with only the IParsable<T> shape Parse(string, IFormatProvider?) or a factory with an optional second parameter threw TargetParameterCountException on deserialization. A single-string overload is now preferred. Otherwise a method is accepted only when every extra parameter is an IFormatProvider (passed the invariant culture) or optional (passed its default), and any other shape is rejected so CanConvert returns false. Fixes #95 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011wnB34hMv7jTvqsaysM9MS
|
This was referenced Sep 27, 2026
This was referenced Sep 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #95
Problem
FindStringConversionMethodaccepted anyFromString/Parse/Create/Convertmethod whose first parameter is astring.ReadandReadAsPropertyNamethen always called it with exactly one argument. SoCanConvertclaimed types it could not deserialize, and deserializing them threwTargetParameterCountException. Two common shapes hit this:IParsable<T>shape,Parse(string, IFormatProvider?)Change
stringoverload is now preferred. Before, whichever overloadGetMethods()returned first was used, and that order is unspecified.IsUsableConversionMethod): a method qualifies only if every parameter after the string is anIFormatProvideror optional. For any other shape, such asCreate(string, int)with a requiredint,CanConvertnow returnsfalse.BuildArguments): anIFormatProviderparameter getsCultureInfo.InvariantCulture, and an optional parameter getsType.Missing, which makes the runtime use its declared default.ReadandReadAsPropertyNameboth use this.ExtraParameterConversionTests:IParsable-shaped round trip, as a value and as a dictionary keyCreate(string, int weight = 7)round trip that gets the default weightIFormatProvideroverloadVerification
TargetParameterCountException. With it in place, they pass. The overload-preference test also failed onmain, which confirms theGetMethods()ordering problem is real.Not included
The triage suggested culture-invariant
IFormattableserialization on the write side as a follow-up. It changes the output format, so I left it out of this PR.🤖 Generated with Claude Code
https://claude.ai/code/session_011wnB34hMv7jTvqsaysM9MS
Generated by Claude Code