IList<T> C# type causes error in generated Dart file

In a Request DTO on my server in C# I have the following

[ApiMember(Name = "ServiceItems", Description = "A list of service item objects. The list must contain at least ONE item.", 
ParameterType = "path", DataType = "Array", IsRequired = true)]
[DataMember(Order = 18)]
public IList<BscServiceItem> ServiceItems { get; set; }

When generating the Dart code with the ServiceStack plugin in Android studio I the the following errors:

  • Undefined class ‘IList’
  • The function ‘IList’ isn’t defined
    The generated Dart Code looks as follows (the lines where the errors are reported)
    /**
    * A list of service item objects. The list must contain at least ONE item.
    */
    // @DataMember(Order=18)
    // @ApiMember(DataType="Array", Description="A list of service item objects. The list must contain at least ONE item.", IsRequired=true, Name="ServiceItems", ParameterType="path")
    IList<BscServiceItem>? serviceItems;

// and a view thousand lines later
    'IList<BscServiceItem>': TypeInfo(TypeOf.Class, create:() => IList<BscServiceItem>()),

If I replace IList<T> with List<T> in C# the generated Code in Dart is OK. I can’t remember having problems with that when creating C# client files from VisualStudio in my old WPF clients…

Is there a general recommendation what types one should avoid when the server must support clients using different programming languages?

You should not use interface properties in DTOs, IList<T> is especially useless since it effectively always referencing a concrete List<T> in practice, which should be used instead. Unless you’re code base utilizes multiple IList<T> implementations there’s no reason to use it, but definitely shouldn’t be leaked into DTOs in the rare case it does.

But if it’s an issue in Dart I’ll need to go back and handle where they’re used to treat them as concrete List<T>, the proper solution is to change it in your DTOs.

Yeah you are right, DTOs are kind of ‘dumb’ data structures, where you usually do not compare, sort etc. I already changed it in the DTOs.

In my server models I use it when I have different Equality operators for a specific implementation of <T>, and in most cases I use IEnumerable<T> anyway.