dotnet / dotnet/dotnet-api-docs

Clarification of exception thrown in transaction scope.

Open
#984 0 comments 0 reactions 0 assignees View on GitHub
area-System.Transactions dotnet-api/prod Pri2 untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

"If no exception occurs within the transaction scope (that is, between the initialization of the TransactionScope object and the calling of its Dispose method), then the transaction in which the scope participates is allowed to proceed. If an exception does occur within the transaction scope, the transaction in which it participates will be rolled back."

Is this intended to mean to rollback you need to exit the transaction scope by an exception and not call scope.Complete()? What about handling the exception within the scope, choosing not to rethrow the exception, and then choosing not to call scope.Complete()? I would expect the transaction to rollback in this case since scope.Complete() was not called but it sounds like it might complete anyway. Which would explain the weird behavior I am having.

---
#### Document Details

⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*

* ID: 039bbc8a-f665-3797-ff12-96cd21682bf3
* Version Independent ID: bbae7fa8-00f9-08dd-d816-ba21092f9df8
* Content: [TransactionScope Class (System.Transactions)](https://docs.microsoft.com/en-us/dotnet/api/system.transactions.transactionscope?view=netframework-4.7.2)
* Content Source: [xml/System.Transactions/TransactionScope.xml](https://github.com/dotnet/dotnet-api-docs/blob/master/xml/System.Transactions/TransactionScope.xml)
* Product: **dotnet-api**
* GitHub Login: @dotnet-bot
* Microsoft Alias: **dotnetcontent**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.