我正在用C#创建一个API,但遇到了无法解释的错误。
"responseStatus": {
"errorCode": "NullReferenceException",
"message": "Object reference not set to an instance of an object.",
"stackTrace": null,
"errors": [],
"meta": null
}
所有其他API调用均以相同的方式工作,但这仅会产生错误。
public class PartnerService : BaseService
{
public IPartnerRepository PartnerRepository { get; set; }
[RequiresAnyRole(Roles.superadmin, Roles.admin)]
public async Task<PartnerListResponse> Get(PartnerListRequest request)
{
var items = await PartnerRepository.GetAllAsync(); // this is the error line
return new PartnerListResponse
{
Items = items
};
}
}
IpartnerRepository
using System;
using System.Collections.Generic;
using System.Text;
using DTO = Ringdesk.Api.ServiceModel.DTO;
namespace Ringdesk.Api.ServiceModel.Interfaces
{
public interface IPartnerRepository : IDtoRepository<DTO.Partner,
DTO.PartnerForInsert, DTO.PartnerForUpdate>
{
}
}
合作伙伴模型
[Route("/partners", Verbs = "GET", Summary = "Retrieve a list of partners")]
public class PartnerListRequest : IReturn<PartnerListResponse>
{
}
public class PartnerListResponse : ResponseBase
{
public List<DTO.Partner> Items { get; set; }
}
为什么会出现此错误?