开发者

Instantiating TransactionScope returns null

开发者 https://www.devze.com 2022-12-11 22:43 出处:网络
I have some VB.NET code that creates a TransactionScope instance: LoggingUtility.LogDebug(\"UpdateCallTable\", \"SatComCallDataImporter\", \"About to associate call data with contracts\")

I have some VB.NET code that creates a TransactionScope instance:

LoggingUtility.LogDebug("UpdateCallTable", "SatComCallDataImporter", "About to associate call data with contracts")
Using ts = New TransactionScope()
    LoggingUtility.LogDebug("UpdateCallTable", "SatComCallDataImporter", "Getting all unimported SatCom calls")

My application is throwing an exception on the call to the creation of a new TransactionScope, with "Object reference not set to an instance of an object.". The exception isn't thrown on my development machine or my test machine; only on the customers production machine, and I have no idea why. I've placed debug lines immediately before and after this line so I'm positive it is this line causing the problem.

A have used TransactionScopes throughout the application 开发者_StackOverflow社区and this is the only place throwing the exception on the client machine.

"About to associate call data with contracts" gets written to the log and the next log entry is the "Object reference not set to an instance of an object".

Code works fine if I move it out of a transaction.

I've been struggling with this for 4 days now and have got no closer.


Perhaps you have an issue with MSDTC?

I'd lean more towards a coding error though, because the TransactionScope object should be initialised and non null, but it will be indicating an error.

Perhaps showing us the code might help us further?

UPDATE: I've had experience with logging engines failing to log the line before an exception, which is sometimes caused by release mode reordering, or the routine doesn't flush actively and the app crashes nastily before it can complete.

I would suggest placing a logging line directly after you using() statement to assert that the TransactionScope is not null. Given the way you have used the code, it is IMPOSSIBLE for the result of that code to return null, the constructor must throw an exception if the constructor fails, otherwise you have a non null transaction scope.

Perhaps a little more code and this test might help some more?

0

精彩评论

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