Feature request for the ServiceStackVS extension

Don’t know how difficult it would be but I would love it if the service reference would bring in at least the System.ComponentModel.DataAnnotations attributes when it brings in the POCO classes.

You can submit Feature Requests on UserVoice.

If you’re referring to DataContract attributes you can add them by enabling AddDataContractAttributes:

/* Options:
Date: 2015-10-07 11:01:27

AddDataContractAttributes: True

You can also export other Attributes in your AppHost with:


This is the code in my AppHost configure override

       Plugins.Add(new AutoQueryFeature { MaxLimit = 5000 });
        Plugins.Add(new NativeTypesFeature());

This is an example of the POCO in the serviceModel
public class UnitOfMeasure

    [Display(AutoGenerateField = true, AutoGenerateFilter = true, ShortName = "UnitMeasKey")]
    public int UnitMeasKey { get; set; }

    [Display(AutoGenerateField = true, AutoGenerateFilter = true, ShortName = "Base")]
    public Int16 Base { get; set; }

    [Display(AutoGenerateField = true, AutoGenerateFilter = true, ShortName = "CompanyID")]
    public string CompanyID { get; set; }

    [Display(AutoGenerateField = true, AutoGenerateFilter = true, ShortName = "MeasType")]
    public Int16 MeasType { get; set; }

    [Display(AutoGenerateField = true, AutoGenerateFilter = true, ShortName = "UnitMeasID")]
    public string UnitMeasID { get; set; }

    [Display(AutoGenerateField = true, AutoGenerateFilter = true, ShortName = "UpdateCounter")]
    public int UpdateCounter { get; set; }


I am not showing any of the display attributes in the exported POCO in the service reference.

Am I doing something wrong?


There’s an issue with trying to use reflection to access [Display] attribute properties where it will throw an Exception if the Order hasn’t been set, I was able to export the [Display] attribute if the order was specified:

public partial class TestAttributeExport
    : IReturn<TestAttributeExport>
    [Display(AutoGenerateField=true, AutoGenerateFilter=true, Order=1, ShortName="UnitMeasKey")]
    public virtual int UnitMeasKey { get; set; }

Exceptions from accessing unintialized Attribute property values are now being swallowed from this commit so Exceptions are now logged and ignored from this commit so they’ll now work without needing to specify the Order.

This change is available from v5.4.1 that’s now available on MyGet.

Ok. I am getting DataContract Attribute and DataMember Attribute but not the Display. What is the option I should be using?

If it’s registered in ExportAttributes collection it should be generated. Add a stand alone project on GitHub showing the issue and I’ll take a look.

Well red faced again. The standalone project I was creating works. Not mine so there is something different between the two. I will go through it and find the issue. I will report my finding in case anyone else has the same issue.

There might be one issue but it is minor. I use using statements above the namespaces. And don’t use the fully qualified type. So every time I need to refresh I have to add the using back to the exported file. I can work around this.

1 Like

You can use the AddNamespaces DTO option to generate additional namespaces in the generated Types, e.g:

/* Options:
AddNamespaces: System.ComponentModel.DataAnnotations

So I was trying to use this feature and it works to a point. The problem is that if the value is false for a property then the property is not set on the export. i.e. [Display(AutoGenerateField = false)] exports an empty Display attribute [Display].

Yeah it only emits non default values, emitting every value would unnecessarily explode the size of each attribute.

I understand not wanting to bloat it but maybe it could emit if it was explicitly set. The AutoGenerateField property of the Display attribute may have a default value but it it not used by UI tools unless it is there.

The metadata reflection API’s only have access to the populated attribute instance, not the expression that specifies which properties were set.

is there a way to mark a property of an object to not be emitted and then use a partial class to add it so that it wont be overwritten?

The way to ignore properties from being serialized is to annotate them with [IgnoreDataMember].

partial classes can’t be used to extend classes in different assemblies, they’re just a C# compiler feature to split a class over multiple source files but they’re compiled together as a single unit and are indistinguishable in .NET from a single file class.