jsii icon indicating copy to clipboard operation
jsii copied to clipboard

C#: JSII cannot infer type for IDictionary

Open JZechy opened this issue 2 years ago • 0 comments

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<string,object> 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

JZechy avatar Jan 16 '24 15:01 JZechy