Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TransactionScope throws exception

Im sure this is so basic question but i can't found any solution on google neither here.

when im trying to use that code block it throws an exception that 'System.Activities.Statements.TransactionScope': type used in a using statement must be implicitly convertible to 'System.IDisposable'

using (TransactionScope trans = new TransactionScope()) { }

Simply, i want to use TransactionScope in Linq code.

Thanks, Regards

like image 987
eerrzz Avatar asked Jan 13 '11 14:01

eerrzz


2 Answers

You are likely using the wrong TransactionScope.

The one you're looking for is System.Transactions.TransactionScope, which resides in the System.Transactions.dll assembly. Make sure it's referenced (it's not by default), and that you are "using System.Transactions".

like image 169
Alex J Avatar answered Sep 21 '22 15:09

Alex J


I don't know what System.Activities.Statements.TransactionScope is but you want System.Transactions.TransactionScope. You'll also need a reference to System.Transactions.dll.

From the documentation:

public sealed class TransactionScope : IDisposable

Note that System.Activities.Statements.TransactionScope lives in System.Activities.Statements which is described as

The System.Activities.Statements namespace contains activities that can be used to create workflows. This namespace contains activities that are used for flow control, interacting with collections and variables, exceptions, compensation, transactions, and interacting with legacy workflows.

which is clearly not appropriate.

like image 22
jason Avatar answered Sep 18 '22 15:09

jason