我认为c#mono实施中存在一个错误。
using (ITransactional transaction = new TransactionalContext ())
using (ITransactional logTransaction =
new TransactionalContext(transaction.Connection ())){
...
}
此类代码不调用TransactionalContext的构造函数,并立即在事务变量上调用Dispose()。
有人可以证实吗?
我正在使用Mono 3.12.1(Windows)
编译此代码一些调查:
这样的代码工作由MS编译器编译并由Mono编译失败
public class DispTest : IDisposable
{
private static int t = 0;
public DispTest()
{
Console.WriteLine("CONSTRUCTOR");
this.Text = "HELLO" + t.ToString();
t += 1;
}
public DispTest(string text)
{
this.Text = text;
Console.WriteLine(text);
}
public string Text { get; set; }
public void Dispose()
{
Console.WriteLine("DISPOSING");
}
}
//in main
using (DispTest t = new DispTest())
using(DispTest t2 = new DispTest(t.Text)){
}
using (DispTest t = new DispTest()){
using(DispTest t2 = new DispTest(t.Text)){
//this code will fail too.
}
}