关于c#:ServiceStack元数据页面抛出MemberAccessException:无法创建抽象类

ServiceStack metadata page throws MemberAccessException: Cannot create an abstract class

假设您有一个请求类AllCustomers,它返回一个IEnumerable

1
2
3
4
[Route("/customers")]
public class AllCustomers : IReturn<IEnumerable<Customer>>
{
}

如果您转到该请求的元数据页,将出现以下崩溃:

1
2
3
4
5
6
7
8
9
10
11
12
[MemberAccessException: Cannot create an abstract class.]
System.Runtime.Serialization.FormatterServices.nativeGetUninitializedObject(RuntimeType type) +0
System.Runtime.Serialization.FormatterServices.GetUninitializedObject(Type type) +56
ServiceStack.Text.<>c__DisplayClass3.<GetConstructorMethodToCache>b__1() +38
ServiceStack.Text.ReflectionExtensions.CreateInstance(Type type) +64
ServiceStack.WebHost.Endpoints.Metadata.JsonMetadataHandler.CreateMessage(Type dtoType) +49
ServiceStack.WebHost.Endpoints.Metadata.BaseMetadataHandler.CreateResponse(Type type) +267
ServiceStack.WebHost.Endpoints.Metadata.BaseMetadataHandler.ProcessOperations(HtmlTextWriter writer, IHttpRequest httpReq, IHttpResponse httpRes) +688
ServiceStack.WebHost.Endpoints.Metadata.BaseMetadataHandler.Execute(HttpContext context) +267
ServiceStack.WebHost.Endpoints.Support.HttpHandlerBase.ProcessRequest(HttpContext context) +84
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +341
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69

我认为,当给定请求的响应是IEnumerable时,元数据页的实现不应该崩溃,因为这是实现服务接口的一种完全有效的方法(而且比返回列表更可取)。如果它将IEnumerable视为返回类型,那么它应该足够智能,以便为samples节实例化一个列表。如果返回类型不可实例化,至少它不应该崩溃…


ServiceStack希望您将响应封装到自己的类中。因此,您将使用Customers-IEnumerable属性创建一个AllCustomerResponse类。