In my C # code, I use nested transaction areas. I have a utility class that creates TransactionScope objects the same way. Both external and internal volumes are constructed in exactly the same way.
If I create TransactionScope objects, such as the first example below, the nested transaction areas work well together:
public static TransactionScope CreateTransactionScope() { var transactionOptions = new TransactionOptions(); transactionOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted; transactionOptions.Timeout = TransactionManager.MaximumTimeout; return new TransactionScope(TransactionScopeOption.Required, transactionOptions); }
However, I get an exception if I create TransactionScope objects as follows:
public static TransactionScope CreateTransactionScope() { var transactionOptions = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted, Timeout = TransactionManager.MaximumTimeout }; return new TransactionScope(TransactionScopeOption.Required, transactionOptions); }
The error reads: "The transaction specified for TransactionScope has a different IsolationLevel value than the value requested for the scope. Parameter name: transactionOptions.IsolationLevel."
Can someone explain to me why using object initialization leads to this behavior?
source share