I have a piece of code as below which works perfectly fine in .net 4.7.2 but gives 'Platform does not support distributed transactions' error in .net 6.
var sefact = cfg.BuildSessionFactory();
using (var scope = new TransactionScope(TransactionScopeOption.Required))
{
using (var session = sefact.OpenSession())
{
session.BeginTransaction();
using (var innerSession = sefact.OpenSession())
{
innerSession.BeginTransaction();
}
}
scope.Complete();
}
Just wanted to know if this is caused by a change which is introduced in System.Transactions.dll in .net 6
I read the below details from somewhere about a change in TransactionScope in .net 6.0.
Transaction Scope Default:
- .NET Framework 4.0: In the .NET Framework 4.0, transactions were implicitly started for various resource managers (such as SQL Server) by default. This means that if you performed database operations using supported providers, they were automatically enlisted in a transaction unless you explicitly opted out.
- .NET 6.0: In .NET 6.0, the behavior of implicit transactions has changed. By default, transactions are not automatically started. You need to explicitly create a
TransactionScopeto participate in a transaction. This change aligns with the more explicit and predictable behavior of .NET Core and .NET 5+.