Azure/azure-service-bus-dotnet

Inconsistent behavior with transactions between .NET Framework and .NET Core

SeanFeldman opened this issue · 1 comments

Scenario

Performing transactional message processing with a database transaction. To avoid ASB client from throwing exceptions, an internal database transaction is wrapped with transaction scope using TransactionScopeOption.Suppress option. This excludes database transaction from participating in the ambient ASB transaction. This works with .NET Framework, but doesn't work with .NET Core.

An exception is thrown - System.NotSupportedException: 'Enlisting in Ambient transactions is not supported.'.

Stacktrace at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) at System.Data.SqlClient.SqlConnection.OpenAsync(CancellationToken cancellationToken) --- End of stack trace from previous location where exception was thrown --- at ReproApp.Program.ExecuteInnerTransaction(String sqlConnectionString) in C:\Users\Sean\Desktop\SuppressScopeRepro\ReproApp\Program.cs:line 72 at ReproApp.Program.Main(String[] args) in C:\Users\Sean\Desktop\SuppressScopeRepro\ReproApp\Program.cs:line 53 at ReproApp.Program.(String[] args)

In other reported occasions 'Local transactions are not supported with other resource managers/DTC.' is reported to be thrown.

Repro project: https://github.com/SeanFeldman/SuppressScopeRepro/

  • SuppressScopeRepro.sln on .NET Framework - doesn't fail
  • SuppressScopeRepro.sln on .NET Core - fails

Versions

  • OS platform and version: Windows 10 / WSL
  • .NET Version: .NET Framework 4.6.1, .NET Core 2.1 / 2.2
  • NuGet package version or commit ID: 3.2.0

For those who find this issue - this is an issue with System.Data.SqlClient.
TransactionScopes are not supported by System.Data.SqlClient versions earlier than 4.5.0.

In my case, used a 3rd party library (Dapper) that referenced earlier version of System.Data.SqlClient. Ironically, Dapper latest version (current for today) is on the older version of System.Data.SqlClient as well 🙂

Closing this issue.