我有以下代码:
using (var transaction = new TransactionScope(TransactionScopeOption.Required,
new TransactionOptions {IsolationLevel = IsolationLevel.ReadCommitted}))
{
try
{
var guid = otherRepository.GetGuid(otherGuid.Value);
var result =
anotherRepository.DeleteFile($"Documents/{guid}/{id}");
result.Message = resultaat.Success ? "success" : resultaat.Message;
result.Success = resultaat.Success;
transaction.Complete();
return Json(result);
}
catch (Exception ex)
{
transaction.Dispose();
ErrorSignal.FromCurrentContext().Raise(ex);
result.Message = "error";
return Json(result);
}
}
奇怪的是,整个try块都被执行了(包括transaction.Complete())。但是之后,代码仍然在catch块的最后一行抛出错误(跳过其余部分!)
该错误显示为:
system.transactions.transactionabortedexception the transaction has aborted
交易完成后如何获得此错误?为什么未捕获?