In my C# code I am using nested transaction scopes. I have a utility class that creates TransactionScope objects identically. Both the outer scope and the inner scope are constructed in exactly the same way.
If I construct the TransactionScope objects like the first example below, the nested transaction scopes play 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 construct the TransactionScope objects like this:
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 than the value requested for the scope. Parameter name: transactionOptions.IsolationLevel".
Can anyone explain to me why using object initialization results in this behavior?