我正在使用servicestack并且遇到自动接线问题。
尝试解析服务“{Service}”或其中一个自动连接的依赖项时出错(有关详细信息,请参阅内部异常)
我不需要帮助确定问题究竟是什么。我真正想要的是一种查看内部异常的方法。内部异常应该告诉我除了问题,我不必弄清楚,但它没有显示在返回的异常或日志中。
设置DebugMode也没有帮助,它只包括最顶层异常的堆栈跟踪。
基本上,如何阻止servicestack隐藏内部异常细节?
答案 0 :(得分:3)
我遇到了同样的问题,结果是在我为特定端点类创建的构造函数内部抛出异常。实施例...
public class PartnerService : Service
{
private PartnerManagementService _partnerManagementService;
public PartnerService()
{
var configuration = new Configuration();
_partnerManagementService = new PartnerManagementService(configuration);
}
public object Get(PartnerGet partner)
{
try
{
var partners = _partnerManagementService.getPartners();
if (!partners.Any())
{
return new HttpError(HttpStatusCode.NotFound, "Partners Could not be found");
}
return partners;
}
catch (Exception e)
{
return new HttpError(HttpStatusCode.InternalServerError, e);
}
}
如果在构造函数内部抛出异常,ServiceStack将无法解析该服务或其依赖项之一,在这种情况下,依赖项是该类的构造函数。
如果你在类的构造函数中放置了try / catch,你可能会得到一个实际上有意义的异常。
答案 1 :(得分:2)
ServiceStack应该已经返回内部异常,即这里是source of the error:
private Exception CreateResolveException<TService>(Exception ex)
{
var errMsg = "Error trying to resolve Service '{0}' or one of its autowired dependencies (see inner exception for details).".Fmt(typeof(TService).FullName);
return new Exception(errMsg, ex);
}
基本上,您的IOC配置存在问题,其中一个依赖项导致错误。
您可以使用以下命令更改ServiceStack以序列化内部异常:
SetConfig(new EndpointHostConfig {
ReturnsInnerException = true,
});
但这已经默认为真。
因此异常应该已经包含内部异常,你指的是什么异常被序列化或代码中抛出的异常?
答案 2 :(得分:0)
一个选项可能是从Github获取实际源代码并将其作为项目添加到您的解决方案中,而不是使用已编译的DLL,然后您可以逐步查看实际代码并查看确切的位置提出异常以及原因。
答案 3 :(得分:0)
我有完全相同的例外。
就我而言,一旦迁移到ServiceStack v4就会发生。使用v3,一切都很完美。
public class AppHost : AppHostBase
{
public AppHost() : base("Northwind web services", typeof(CustomersService).Assembly)
{ }
public override void Configure( Container container )
{
SetConfig(new HostConfig
{
DebugMode = true,
ReturnsInnerException = true,
});
var dbFactory = new OrmLiteConnectionFactory("~/Northwind.sqlite".MapHostAbsolutePath(), SqliteDialect.Provider);
container.Register(dbFactory);
// Dependencies
container.RegisterAs<CustomerEntityRepository, ICustomerEntityRepository>();
container.RegisterAutoWired<CustomersService>();
}
}
public abstract class Repository<TEntity> : IRepository<TEntity> where TEntity : IEntity, new()
{
protected IDbConnectionFactory dbFactory { get; set; }
public Repository( IDbConnectionFactory factory )
{
dbFactory = factory;
}
}
public class CustomerEntityRepository : Repository<CustomerEntity>, ICustomerEntityRepository
{
public CustomerEntityRepository( IDbConnectionFactory dbFactory )
: base(dbFactory)
{
}
}
}
我找到的唯一解决方案是:
container.RegisterAs<ICustomerEntityRepository>(c => new CustomerEntityRepository(dbFactury));
此处返回完整的异常消息http://pastebin.com/jJntNN5p