开发者

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.Activiti开发者_StackOverflow中文版es.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


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".


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.


You are using the wrong TransactionScope class. The right one is in the System.Transactions namespace. Your error indicates that you are using another class from System.Activities.Statements.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜