Codegen for arrays of nullable value types

After updating our project from ServiceStack 6.5 to 6.9, I’ve encountered some erroneous code when generating the C# code from our service.

The DTO has property:

public byte?[] StatusBetween { get; set; }

The generated code is:

public virtual Nullable[] StatusBetween { get; set; }

Which is invalid.

As far as I can tell so far it only impacts nullable array of byte, nullable array of DateTime and nullable array of decimal types.

It seems to stem from the fact our underlying MSSQL tables we generate the AutoQuery DTOs from (via T4 templates) have nullable columns of type smallint, DateTime and decimal. Those DTO’s and AutoQuery DTOs are fine - it’s just using generating the code for a client to consume the API that has a problem.

I’m currently deciding if those columns really should be nullable, so I might be able to work around it - but thought I’d mention the issue here in case it’s something silly I’m doing.

This should now be supported in the latest v6.9.1 that’s now available on MyGet.

Thanks - tested this on 6.91 and can confirm it is working as expected now.

On an unrelated note, the Ignore property attributes on my Request DTO’s are no longer coming through on the generated code.

So, in my request DTO I have:

[Tag("Journal Sets")]
[Field(nameof(SetNo), Ignore = true)]	
public class JournalSetPATCHRequest : JournalSet, IReturn<JournalSet>
{
	[System.Runtime.Serialization.IgnoreDataMember]
	public override string SetNo { get; set; }	
	...
}

As I want the SetNo property to not be visible in the AutoUI form, and it generates code like this for the client in 6.5:

[Route("/JournalSets/{JournalSetID}", "PATCH")]
[Field(Ignore=true, Name="SetNo")]
public partial class JournalSetPATCHRequest	: JournalSet, IReturn<JournalSet>
{
	[IgnoreDataMember]
	public virtual string SetNo { get; set; }
...
}

But in 6.9.1 the Field attribute with the Ignore=true is missing:

[Route("/JournalSets/{JournalSetID}", "PATCH")]
public partial class JournalSetPATCHRequest	: JournalSet, IReturn<JournalSet>
{
	[IgnoreDataMember]
	public virtual string SetNo { get; set; }
...
}

EDIT: I should point out I’m not sure if I really care that the generated code goesn’t have this attribute - I do care if the Auto UI form doesn’t hide the fields, but I’m not sure yet if that is or is the case - I’m having an issue which means none of my AutoUI forms are displaying so I don’t know - the browser shows me this:

That’s because they’re already included in the /metadata/app.json and don’t need to be emitted as generic attributes.

You can export Attributes by configuring the NativeTypesFeature plugin:

ConfigurePlugin<NativeTypesFeature>(feature => {
    feature.MetadataTypesConfig.ExportAttributes.Add(typeof(FieldAttribute));
});

But this will make the metadata larger and it looks like you’re already exceeding the maximum size allowed. You can try clearing your localStorage cache in Chrome’s Web Developer / Application panel to free up some space in your localStorage for http://localhost site.

I’ve emptied the local storage of my browser (Edge) and still get the same error.

This does not occur with 6.5. I’ve previously bumped up against size issues of our API, and been putting off splitting up into microservices or finding a way to opt-in service exposure - It looks like I’m going to have to get serious about it now!
Our API is up to just over 1000 routes now, so I don’t think I can put it off any longer :slight_smile:

Thanks for your help!

1 Like