Repository navigation
[patch] Skip conversion methods that cannot produce the type, so a working Parse is used - #114
Conversation
…rking Parse is used IsUsableConversionMethod accepted a method whose return type only shared T's generic type definition (Box<string>.FromString for Box<int>), and open generic methods that were closed over T only later, in the converter's static initializer. Either one won over a usable Parse(string) and then failed on every read: an InvalidCastException, or a TypeInitializationException that broke the converter for the rest of the process. Generic candidates are now closed over the type while searching, and dropped if that fails; the return type must be exactly the type. The unreachable AmbiguousMatchException fallback, which carried a second copy of the loose return-type check, is removed. Fixes #104 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013JBDCsjuRez5zdzBcBJ7Y7
|
CI is blocked by runner availability, not by this change. In run 37363469055, #113 here and ktsu-dev/Sorting#65 show the same cancellation at the same time, so it looks like an org-wide Actions capacity or limit issue. Locally the full suite passes (121/121) on this branch. Once runners are available, CI needs to be re-run. Generated by Claude Code |
|



Fixes #104
What changed
IsUsableConversionMethodaccepted two kinds of method that can never work, and becauseFromStringis tried beforeParse, either one hid a usableParse(string):T's generic type definition, soBox<string> FromString(string)was accepted forBox<int>. Every read then threwInvalidCastException.MakeGenericMethod(typeof(T)). WhenTbroke a constraint, that threwTypeInitializationExceptionand brokeRoundTripStringJsonConverter<T>for the rest of the process.FindStringConversionMethodnow does the following:CloseOverTypehelper, and drops it if closing throws. That happens when a constraint is violated or the method has more than one type parameter.IsUsableConversionMethodnow requires the return type to be exactly the type.FindStringConversionMethodreturns the closed method, so the converter uses it directly andCreateStringConversionMethodis gone.catch (AmbiguousMatchException)block is removed. It could not be reached, and it carried a second copy of the loose return-type check. A stale comment inEdgeCaseTeststhat referred to it is updated.The existing
TestGenericClass<int>.FromString<TSelf>case still resolves, because closing it over the type yields a method that returns exactly that type.Tests
Two tests in
ConversionMethodPriorityTestscover the two shapes from the issue:BoxWithMismatchedFromString<int>:FromStringreturns the<string>closureCodeWithConstrainedGenericFromString:FromString<TEncoding>has astruct, ITestEncodingconstraintBoth now deserialize through
Parse. With the library change reverted, both tests fail, withInvalidCastExceptionandTypeInitializationExceptionrespectively. With the change, the full suite passes (121/121, net10.0), and the library builds for all its target frameworks.This PR is independent of #113 (stack-trace preservation). The two edit different parts of
RoundTripStringJsonConverter.cs.🤖 Generated with Claude Code
https://claude.ai/code/session_013JBDCsjuRez5zdzBcBJ7Y7
Generated by Claude Code