3
votes

If I have a base class for my services like

public abstract class BaseService<T,R> : ServiceStack.ServiceInterface.Service
{
    public R Get(T request)
    {
    }
}

Then service stack crashes with

An attempt was made to load a program with an incorrect format.

I think Servicestack should ignore the abstract generic classes when registering services. Is there any way to tell servicestack to ignore some service classes ?

1
Can you log issues with ServiceStack in the Project's GitHub issues listmythz
I worked around this by renaming the Get method in the base class to GetBase and adding a Get method in the deriven class that calls the GetBase methoduser1661621
Sounds good. Can you edit your question to include this workaround? thx. I'll look into preventing the error in ServiceStack.mythz
@user1661621 Are you absolutely sure about that the abstract class is causing the error? That error message usually means that there are mixed 32 and 64 bit assemblies being loaded. Can you provide a failing test?Per

1 Answers

2
votes

By default, ServiceStack is including all types in the assemblies as candidates for services. It gets that exception when it tries to instantiate the class.

By overriding the CreateServiceManager in the host class, you can inject your own filtering of types so that abstract and unclosed generics are excluded.

    protected override ServiceManager CreateServiceManager(params Assembly[] assembliesWithServices)
    {
        return new ServiceManager(
            new Container(),
            new ServiceController(
                () =>
                assembliesWithServices.SelectMany(
                    assembly => assembly.GetTypes().Where(t => !t.IsAbstract && !t.IsGenericTypeDefinition))));
    }