Include for Collection type missing

On my server I defined a DTO containing an OrderedDictionary collection:

[ApiMember(Name = "VersionHistory", Description = "Read-only property. Version history of this application containing only changes of master or minor versions.  Set automatically by the system.",  ParameterType = "path", DataType = "List<string>")]
public OrderedDictionary VersionHistory { get; set; }

When generating the ServiceStack Reference file in the client, it generates the code correctly but does not create the necessary using directives.

It should add:

using System.Collections.Generic;
using System.Collections.Specialized;

Am I missing something?

You shouldn’t be using specialized collection implementations in your Service Contract which should just be defined using plain POCO data models and collections. This wont work in non .NET clients which doesn’t have the specialized collection implementation. In general non-generic collection types like OrderedDictionary where both keys/values are “unknown” objects will also have issues in different serializers as well (and also not supported in most non .NET langs).

If you insist on using it, you can add the missing namespace with the AddNamespaces option:

AddNamespaces: System.Collections.Specialized

Alternatively you can force adding the namespace by default in your AppHost Configure() with:

var nativeTypes = this.GetPlugin<NativeTypesFeature>();
nativeTypes.MetadataTypesConfig.AddNamespaces = new List<string>

But I wouldn’t be using it at all in your Service Contracts which makes your service less interoperable.

Hi Demis,
Yeah, I changed my implementation in the meantime to a List<string> member which is a bit more complicated to use in my business logic but for sure better suited for the API.

However, interesting information about how to force adding namespaces in the AppHost.Configure() method. I was not aware of such a possibility.

Thanks for this information.

1 Like