Fix JS array → C# generic collection conversion in CLR interop#2384
Merged
Conversation
Closed
… and MethodInfoFunction Agent-Logs-Url: https://github.com/sebastienros/jint/sessions/a0cdbe69-2cee-46f9-bdf3-384e7049081e Co-authored-by: lahma <171892+lahma@users.noreply.github.com>
…ltTypeConverter and InteropHelper Agent-Logs-Url: https://github.com/sebastienros/jint/sessions/a0cdbe69-2cee-46f9-bdf3-384e7049081e Co-authored-by: lahma <171892+lahma@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix conversion issues in TreeItemData initialization
Fix JS array → C# generic collection conversion in CLR interop
Apr 6, 2026
lahma
approved these changes
Apr 6, 2026
lahma
marked this pull request as ready for review
April 6, 2026 16:55
lahma
enabled auto-merge (squash)
April 6, 2026 16:56
This was referenced Apr 13, 2026
This was referenced Jun 8, 2026
This was referenced Jun 29, 2026
This was referenced Jul 7, 2026
This was referenced Jul 13, 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.
Passing a JS array to a CLR constructor or method expecting
List<T>,IList<T>,IEnumerable<T>, or related collection types threwInvalidCastException: Object must implement IConvertible.Root causes
Two independent bugs, both stemming from
object[](the.ToObject()representation of aJsArray) incorrectly satisfying generic type checks meant for already-compatible types:DefaultTypeConverter.TryConvert: The early generic assignability check returnedtrueforobject[] → IList<string>becauseobject[]does implementIList<>(withobject, notstring). This causedconverted = object[]to be returned unchanged, failing at invocation.MethodInfoFunction.IsGenericParameter: Returnedtruefor the same reason, settingparameters[i] = object[]without conversion and lettingMethodBase.Invokethrow.Changes
DefaultTypeConverter.TryConvert: Addedobject[]→ generic collection conversion (coveringList<T>,IList<T>,ICollection<T>,IEnumerable<T>,IReadOnlyList<T>,IReadOnlyCollection<T>,Collection<T>). Placed before the generic assignability check to prevent the incorrect early return.MethodInfoFunction.IsGenericParameter: For fully concrete generic types (!ContainsGenericParameters), now also verifiesparameterType.IsAssignableFrom(argObj.GetType())before taking the direct-assignment path.InteropHelper.CalculateMethodParameterScore: JS array → generic collection parameter now scores 2 (same as JS array → C# array).InteropHelper: Extracted a staticHashSet<Type> GenericCollectionTypeDefinitionsfor O(1) lookups, shared withDefaultTypeConverter.fixes #2383