I’m doing a series of async/await related blog post on the particular blog. This one might also be interesting for you.
You might not know this, but the 4.5.0 version of the .NET Framework contains a serious bug regarding System.Transactions.TransactionScope and how it behaves with
async/await. Because of this bug, a
TransactionScopecan’t flow through into your asynchronous continuations. This potentially changes the threading context of the transaction, causing exceptions to be thrown when the transaction scope is disposed.
This is a big problem, as it makes writing asynchronous code involving transactions extremely error-prone.
The good news is that as part of the .NET Framework 4.5.1, Microsoft released the fix for that “asynchronous continuation” bug. The thing is that developers like us now need to explicitly opt-in to get this new behavior. Let’s take a look at how to do just that.
- If you are using
async/awaittogether, you should really upgrade to .NET 4.5.1 right away.
TransactionScopewrapping asynchronous code needs to specify
TransactionScopeAsyncFlowOption.Enabledin its constructor.
If you want to learn more about async/await and how to flow TransactionScopes over continuations, I suggest you read the full blog post originally posted on the particular blog.