Repository navigation
TransactionScope in 2.1 throwing exception only during debugging in VS2017 15.7.0 Preview 6.0 #21
Description
Activity
dotnet --info
.NET Core SDK (reflecting any global.json): Version: 2.1.300-rc1-008673 Commit: f5e3ddbe73 Runtime Environment: OS Name: Windows OS Version: 6.3.9600 OS Platform: Windows RID: win81-x64 Base Path: C:\Program Files\dotnet\sdk\2.1.300-rc1-008673\ Host (useful for support): Version: 2.1.0-rc1 Commit: eb9bc92051 .NET Core SDKs installed: 1.0.0 [C:\Program Files\dotnet\sdk] 1.0.4 [C:\Program Files\dotnet\sdk] 1.1.0-preview1-005098 [C:\Program Files\dotnet\sdk] 1.1.0 [C:\Program Files\dotnet\sdk] 1.1.8 [C:\Program Files\dotnet\sdk] 2.0.3 [C:\Program Files\dotnet\sdk] 2.1.4 [C:\Program Files\dotnet\sdk] 2.1.104 [C:\Program Files\dotnet\sdk] 2.1.200-preview-007597 [C:\Program Files\dotnet\sdk] 2.1.300-rc1-008673 [C:\Program Files\dotnet\sdk] .NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.0-rc1-final [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.0-rc1-final [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 1.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.0-rc1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-downloadDistributed transactions are not supported yet - see #16755
That is part of the bug. This code should never try to elevate to use Distributed transactions. It seems to do it only if you add the breakpoints and stop during debugging.
If you just execute, there is no Distributed transaction and it works just fine.
This looks to be an issue with System.Data, based on this part of the callstack:
at System.Transactions.TransactionInterop.GetExportCookie(Transaction transaction, Byte[] whereabouts)
at System.Data.SqlClient.SqlInternalConnection.GetTransactionCookie(Transaction transaction, Byte[] whereAbouts)
at System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction tx)
at System.Data.ProviderBase.DbConnectionPool.PrepareConnection(DbConnection owningObject, DbConnectionInternal obj, Transaction transaction)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry)
at System.Data.SqlClient.SqlConnection.Open()System.Data is asking for the "ExportCookie" for the transaction. That can only be obtained after promoting the transaction.
System.Data should be trying to do a Transaction.EnlistPromotableSinglePhase first, before asking for the Export Cookie. But if EnlistPromotableSinglePhase returns "false", that means that a call to EnlistDurable or another EnlistPromotableSinglePhase has already been made for the transaction. This could lead to System.Data trying to get the Export Cookie.
Adding label for area-System.Data.SqlClient and adding @saurabh500
Reacted by WenJun ChiIs this something that will be fixed as part of the 2.1 release?
Hi @BrotherOdin
I am unable to repro the issue using the repro code you provided in my enviornment, I have stripped down the repro you provided to a bare minimum where it uses .NET SDK Runtime Version2.1.300-rc1-008673and SqlClient Version4.5.0-rc1.
I have tried both running it viacommand promptandplacing debug breakpointsusing Visual Studio, however I still cannot repro the issue.
I have attached the Visual Studio solution of the minimal repro, could you kindly try the same and let me know if you see the exception in your environment ?
adhoc_gh_29633.zipPS D:\adhoc_gh_29633> dotnet --info .NET Core SDK (reflecting any global.json): Version: 2.1.300-rc1-008673 Commit: f5e3ddbe73 Runtime Environment: OS Name: Windows OS Version: 10.0.17134 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\2.1.300-rc1-008673\ Host (useful for support): Version: 2.1.0-rc1 Commit: eb9bc92051 .NET Core SDKs installed: 2.1.300-preview2-008533 [C:\Program Files\dotnet\sdk] 2.1.300-rc1-008673 [C:\Program Files\dotnet\sdk] .NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.0-preview2-final [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.0-rc1-final [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.0-preview2-final [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.0-rc1-final [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.0-preview2-26406-04 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.0-rc1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download PS D:\adhoc_gh_29633>
PS D:\adhoc_gh_29633> cat .\adhoc.csproj <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp2.1</TargetFramework> <RuntimeFrameworkVersion>2.1.0-rc1</RuntimeFrameworkVersion> </PropertyGroup> <ItemGroup> <PackageReference Include="System.Data.SqlClient" Version="4.5.0-rc1" /> </ItemGroup> </Project> PS D:\adhoc_gh_29633>
I will try it and report back. Stay tuned.
The one in the ZIP is using System.Data.SqlClient (4.6.0-preview1-26529-04) rather than 4.5.0-rc1 so I could not try it.
Once I update it back to 4.5.0-rc1, I am able to recreate the problem.
This are the steps I followed.
Updated adhoc.csproj to use 4.5.0-rc1. (Basically the same as you referenced above)
Open Visual Studio Enterprise 2017 Preview Version 15.8.0 Preview 6.0
Open Solution
Compile
Set the two breakpoints as indicated in the code
F5 to Run - Hits first breakpoint
F10 - To step through until it hits this line: connection.Open();
Exception thrown.We can do an interactive session if you would like. Just let me know.
@BrotherOdin Thank you for the confirmation and detailed steps to repro the issue. I see we differ in OS environments, your logs suggest you are using
win81-x64while I am trying to repro the issue inwin10-x64. I will try to setup and repro the issue inwin81-x64environment and get back to you.I think I'm running into a similar issue... although it's kind of intermittent. Sometimes I'll get the error and sometimes I don't. And it doesn't just happen when a breakpoint is set. I know this doesn't really help with troubleshooting but I wanted to let you know that I'm experiencing it too.
@SimplerSoftware Thank you for sharing the information. Could you kindly share your
dotnet --infooutput as well.@keeratsingh - here you go:
.NET Core SDK (reflecting any global.json): Version: 2.1.300 Commit: adab45bf0c Runtime Environment: OS Name: Windows OS Version: 10.0.17134 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\2.1.300\ Host (useful for support): Version: 2.1.0 Commit: caa7b7e2ba .NET Core SDKs installed: 1.1.0 [C:\Program Files\dotnet\sdk] 2.0.0 [C:\Program Files\dotnet\sdk] 2.0.2 [C:\Program Files\dotnet\sdk] 2.0.3 [C:\Program Files\dotnet\sdk] 2.1.1-preview-007094 [C:\Program Files\dotnet\sdk] 2.1.2 [C:\Program Files\dotnet\sdk] 2.1.4 [C:\Program Files\dotnet\sdk] 2.1.100 [C:\Program Files\dotnet\sdk] 2.1.101 [C:\Program Files\dotnet\sdk] 2.1.103 [C:\Program Files\dotnet\sdk] 2.1.104 [C:\Program Files\dotnet\sdk] 2.1.200-preview-007474 [C:\Program Files\dotnet\sdk] 2.1.200-preview-007589 [C:\Program Files\dotnet\sdk] 2.1.200 [C:\Program Files\dotnet\sdk] 2.1.201 [C:\Program Files\dotnet\sdk] 2.1.300-preview1-008174 [C:\Program Files\dotnet\sdk] 2.1.300-rc1-008673 [C:\Program Files\dotnet\sdk] 2.1.300 [C:\Program Files\dotnet\sdk] .NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.0-preview1-final [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.0-rc1-final [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.0-preview1-final [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.0-rc1-final [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 1.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.0-preview1-26216-03 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.0-rc1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]Edit: Formatted response by @keeratsingh
I have setup a Windows 8.1 environment and was able to repro the issue only once against a local 2017 SQLServer, that too on a clean VM, fortunately I was able to capture the dump and trace with the line numbers to have a better picture of the path. I haven't been able to repro this on Windows 10.
On further investigation while debugging through code I found thatSystem.Data.SqlClientis indeed calling Transaction.EnlistPromotableSinglePhase before it calls GetTransactionCookie.- If the
EnlistPromotableSinglePhasemethod call returnstrue, the exception is not seen. - However if I simulate
EnlistPromotableSinglePhasewere to returnfalseby calling theEnlistNonNullmethod explicitly againsecond time, theEnlistPromotableSinglePhasemethod call returnsfalse, that is when the GetTransactionCookie method gets called and the expection is seen, which is inline with @jimcarley 's comments above.
Now the above is just a theory, so far which I have not been able to confirm if
EnlistNonNullis indeed being called twice, since the issue is not reproable consistently.@BrotherOdin Is the issue reproing consistently for you ? Also, to confirm which version of SQLServer are you seeing this issue with, is it local or remote SQLServer ?
at System.Transactions.Distributed.DistributedTransactionManager.GetDistributedTransactionFromTransmitterPropagationToken(Byte[] propagationToken) in E:\A\_work\165\s\corefx\src\System.Transactions.Local\src\System\Transactions\DistributedTransaction.cs:line 45 at System.Transactions.TransactionInterop.GetDistributedTransactionFromTransmitterPropagationToken(Byte[] propagationToken) in E:\A\_work\165\s\corefx\src\System.Transactions.Local\src\System\Transactions\TransactionInterop.cs:line 310 at System.Transactions.TransactionStatePSPEOperation.PSPEPromote(InternalTransaction tx) in E:\A\_work\165\s\corefx\src\System.Transactions.Local\src\System\Transactions\TransactionState.cs:line 4542 at System.Transactions.TransactionStateDelegatedBase.EnterState(InternalTransaction tx) in E:\A\_work\165\s\corefx\src\System.Transactions.Local\src\System\Transactions\TransactionState.cs:line 3333 at System.Transactions.EnlistableStates.Promote(InternalTransaction tx) in E:\A\_work\165\s\corefx\src\System.Transactions.Local\src\System\Transactions\TransactionState.cs:line 682 at System.Transactions.Transaction.Promote() in E:\A\_work\165\s\corefx\src\System.Transactions.Local\src\System\Transactions\Transaction.cs:line 1131 at System.Transactions.TransactionInterop.ConvertToDistributedTransaction(Transaction transaction) in E:\A\_work\165\s\corefx\src\System.Transactions.Local\src\System\Transactions\TransactionInterop.cs:line 42 at System.Transactions.TransactionInterop.GetExportCookie(Transaction transaction, Byte[] whereabouts) in E:\A\_work\165\s\corefx\src\System.Transactions.Local\src\System\Transactions\TransactionInterop.cs:line 86 at System.Data.SqlClient.SqlInternalConnection.GetTransactionCookie(Transaction transaction, Byte[] whereAbouts) in E:\A\_work\4\s\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\SqlInternalConnection.cs:line 593 at System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction tx) in E:\A\_work\4\s\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\SqlInternalConnection.cs:line 458 at System.Data.ProviderBase.DbConnectionPool.PrepareConnection(DbConnection owningObject, DbConnectionInternal obj, Transaction transaction) in E:\A\_work\4\s\corefx\src\System.Data.SqlClient\src\System\Data\ProviderBase\DbConnectionPool.cs:line 1228 at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) in E:\A\_work\4\s\corefx\src\System.Data.SqlClient\src\System\Data\ProviderBase\DbConnectionPool.cs:line 1216 at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) in E:\A\_work\4\s\corefx\src\System.Data.SqlClient\src\System\Data\ProviderBase\DbConnectionPool.cs:line 1043 at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) in E:\A\_work\4\s\corefx\src\System.Data.SqlClient\src\System\Data\ProviderBase\DbConnectionFactory.cs:line 151 at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) in E:\A\_work\4\s\corefx\src\Common\src\System\Data\ProviderBase\DbConnectionInternal.cs:line 325 at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) in E:\A\_work\4\s\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\SqlConnection.cs:line 1153 at System.Data.SqlClient.SqlConnection.Open() in E:\A\_work\4\s\corefx\src\System.Data.SqlClient\src\System\Data\SqlClient\SqlConnection.cs:line 689 at adhoc.DataStore.get_Connection() in C:\Users\win81user\Downloads\adhoc_gh_29633\adhoc\DataStore.cs:line 38 at adhoc.gh_29633_TransactionScopeExecption.Main(String[] args) in C:\Users\win81user\Downloads\adhoc_gh_29633\adhoc\gh_29633_TransactionScopeExecption.cs:line 20
- If the
13 remaining items
As recently announced in the .NET Blog, focus on new SqlClient features an improvements is moving to the new Microsoft.Data.SqlClient package. For this reason, we are moving this issue to the new repo at https://github.com/dotnet/SqlClient. We will still use https://github.com/dotnet/corefx to track issues on other providers like System.Data.Odbc and System.Data.OleDB, and general ADO.NET and .NET data access issues.
do we have any solution
I am running in same issue
with .net core 2.2Hi @BrotherOdin @sushantraje2000 @zhangsquall @Alchemy86 @ciragithub
I tested this issue today with provided repro application and I was able to reproduce issue with EF Core v2.1.0-rc1-final
But I tried again with EF Core v3.1.9 (tested both netcoreapp2.1 and netcoreapp3.1) that references Microsoft.Data.SqlClient now and this issue seems to be resolved.Could someone verify and confirm so we can close this issue?
Thanks!
@David-Engel @DavoudEshtehari
I wonder if this can be closed since there is no activity or reports of the same?Reacted by DavoudEshtehariClosing due to inactivity. Feel free to comment if still experiencing the issue.
- added a commit that references this issue
on Jun 17, 2026 - added a commit that references this issue
on Jun 25, 2026
While testing the .net core 2.1 implementation of TransactionScope I ran into the following issue.
We have a library that configures settings for DB Connections and Transaction scope (Data.Core). Other libraries call this library to execute queries using dapper.
When I execute the code without the debugger, everything runs fine. When I set a breakpoint in the unit test AND also in the method where the DB connection is opened. I then get the exception below.
Any ideas?
This is the test method in Data.Core.Tests:
This is DataStore class:
I have attached a project to reproduce the error.
Debugger.Issue.zip
[EDIT] Add C# syntax highlighting by @karelz