C#: JSII cannot infer type for IDictionary
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 267
- Avg merge
- 1d 25m
- Merged PRs (30d)
- 14
Description
### Describe the bug
When LINQ method `ToDictionary()` is used, it returns a dictionary, that is described by reflection as `IDictionary<,>`. When this type is used as a parameter for `BuildSpec.FromObject()`, JSII runs in to problems to recognize correct type throwing `ArgumentException`:
```
System.ArgumentException: Could not infer JSII type for .NET type 'IDictionary`2' (Parameter 'type')
```
### Expected Behavior
Method `BuildSpec.FromObject()` is described in C# implementation of CDK as:
```
public static BuildSpec FromObject(IDictionary value)
```
I would expect one of two things in this case:
- JSII can handle interface type.
- C# implementation will not allow to use interface type.
### Current Behavior
Although CDK method is described that it can receive `IDictionary`, argument type cannot be described by C# reflection as interface.
### Reproduction Steps
Pass to the `BuildSpec.FromObject()` any dictionary created through LINQ method `ToDictionary()`.
### Possible Solution
_No response_
### Additional Information/Context
_No response_
### SDK version used
2.121.1
### Environment details (OS name and version, etc.)
Fedora 39
Contributor guide
Research direction
Start by reproducing the failure with a LINQ ToDictionary() result passed to BuildSpec.FromObject(), using the reported SDK version and environment if available. Trace the JSII .NET type-inference path from the IDictionary`2 exception and compare it with the declared IDictionary parameter. Done means the interface type is handled correctly or the public C# signature no longer accepts it, with regression coverage for the reproduction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100