Class is missing from generated code

Hi,

I am using the Add ServiceStack Reference Visual Studio plugin and I’m trying to generate only some classes from my service model by using the IncludeTypes option. It works well for most cases however I had an issue with a request that returns a list of DTO. I know that this is not best practice however I cannot change this code without breaking the compatibility.

I found an unusual issue while trying to reproduce the behavior in a separate project:

If I use the following code:

    public partial class ReturnedDto
    {
        public virtual int Id { get; set; }
    }

    [Route("/Request1/", "GET")]
    public partial class GetRequest1
        : IReturn<List<ReturnedDto>>, IGet
    {
    }

    // Service
    public object Any(GetRequest1 request)
    {
        return null;
    }

Options:

IncludeTypes: GetRequest1,ReturnedDto

I get the expected behavior e.g.: GetRequest1 and ReturnedDto are present in the generated code. However if I add another request that returns the DTO, only GetRequest1 is generated.

    public partial class ReturnedDto
    {
        public virtual int Id { get; set; }
    }

    [Route("/Request1/", "GET")]
    public partial class GetRequest1
        : IReturn<List<ReturnedDto>>, IGet
    {
    }

    [Route("/Request2", "GET")]
    public partial class GetRequest2
        : IReturn<ReturnedDto>, IGet
    {
    }
    // Service
    public object Any(GetRequest1 request)
    {
        return null;
    }
    public object Any(GetRequest2 request)
    {
        return null;
    }

Options:

IncludeTypes: GetRequest1,ReturnedDto

Can you tell me why the class ReturnedDto is not always generated? I guess this is related to the non best practice use of returning a list.

I tested with the latest ServiceStack version.

When you add GetRequest2, are you still using:

IncludeTypes: GetRequest1,ReturnedDto

Or including it in the list?

IncludeTypes: GetRequest1,GetRequest2,ReturnedDto

I am not including it in the list. For this example, I only want GetRequest1 and ReturnedDto to be generated.

I’m not able to repro this behavior, are you using the latest version?

I’ve added these DTOs to the Test project in this commit and deployed it to http://test.servicestack.net

Which is returning the expected generated types, e.g:

http://test.servicestack.net/types/csharp?IncludeTypes=GetRequest1,ReturnedDto

/* Options:
Date: 2016-10-11 20:50:37
Version: 4.00
Tip: To override a DTO option, remove "//" prefix before updating
BaseUrl: http://test.servicestack.net

//GlobalNamespace: 
//MakePartial: True
//MakeVirtual: True
//MakeInternal: False
//MakeDataContractsExtensible: False
//AddReturnMarker: True
//AddDescriptionAsComments: True
//AddDataContractAttributes: False
//AddIndexesToDataMembers: False
//AddGeneratedCodeAttributes: False
//AddResponseStatus: False
//AddImplicitVersion: 
//InitializeCollections: True
IncludeTypes: GetRequest1,ReturnedDto
//ExcludeTypes: 
//AddNamespaces: 
//AddDefaultXmlNamespace: http://schemas.servicestack.net/types
*/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using ServiceStack;
using ServiceStack.DataAnnotations;
using Test.ServiceInterface;


namespace Test.ServiceInterface
{

    [Route("/Request1", "GET")]
    public partial class GetRequest1
        : IReturn<List<ReturnedDto>>, IGet
    {
    }

    public partial class ReturnedDto
    {
        public virtual int Id { get; set; }
    }
}

http://test.servicestack.net/types/csharp?IncludeTypes=GetRequest1,GetRequest2,ReturnedDto

/* Options:
Date: 2016-10-11 20:51:51
Version: 4.00
Tip: To override a DTO option, remove "//" prefix before updating
BaseUrl: http://test.servicestack.net

//GlobalNamespace: 
//MakePartial: True
//MakeVirtual: True
//MakeInternal: False
//MakeDataContractsExtensible: False
//AddReturnMarker: True
//AddDescriptionAsComments: True
//AddDataContractAttributes: False
//AddIndexesToDataMembers: False
//AddGeneratedCodeAttributes: False
//AddResponseStatus: False
//AddImplicitVersion: 
//InitializeCollections: True
IncludeTypes: GetRequest1,GetRequest2,ReturnedDto
//ExcludeTypes: 
//AddNamespaces: 
//AddDefaultXmlNamespace: http://schemas.servicestack.net/types
*/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using ServiceStack;
using ServiceStack.DataAnnotations;
using Test.ServiceInterface;


namespace Test.ServiceInterface
{

    [Route("/Request1", "GET")]
    public partial class GetRequest1
        : IReturn<List<ReturnedDto>>, IGet
    {
    }

    [Route("/Request2", "GET")]
    public partial class GetRequest2
        : IReturn<List<ReturnedDto>>, IGet
    {
    }

    public partial class ReturnedDto
    {
        public virtual int Id { get; set; }
    }
}

I see a difference between your GetRequest2 and mine: it returns a list of ReturnedDto while mine return a ReturnedDto. I uploaded my test project here if you want to download it: https://www.dropbox.com/s/cj9arveh7b86f8y/WebApplication1.zip?dl=0

I am using the latest version.

Were you able to reproduce the issue with my test project?

This issue is because the ReturnedDto is defined as a Response DTO for a different Service which isn’t being included in the list, where excluding that Service excludes its definition. I’ve added a workaround to support this scenario in this commit.

This change is available from v4.5.1 that’s now available on MyGet.

Thanks for the quick fix as always.