实例化 TransactionScope 返回 null

发布于 2024-08-12 05:31:59 字数 643 浏览 7 评论 0原文

我有一些创建 TransactionScope 实例的 VB.NET 代码:

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

我的应用程序在调用创建新 TransactionScope 时抛出异常,并显示“对象引用未设置为对象的实例。”。我的开发机器或测试机器上没有抛出异常;仅在客户生产的机器上,我不知道为什么。我已在该行之前和之后放置了调试行,因此我确信是该行导致了问题。

A 在整个应用程序中使用了 TransactionScope,这是在客户端计算机上抛出异常的唯一地方。

“即将将调用数据与合同关联”被写入日志,下一个日志条目是“对象引用未设置到对象的实例”。

如果我将代码移出事务,则代码可以正常工作。

我已经为此苦苦挣扎了四天,但仍没有任何进展。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

静若繁花 2024-08-19 05:31:59

也许您对 MSDTC 有疑问?

不过,我更倾向于编码错误,因为 TransactionScope 对象应该初始化并且非空,但它会指示错误。

也许向我们展示代码可以进一步帮助我们?

更新:我有过日志引擎无法在异常之前记录行的经验,这有时是由发布模式重新排序引起的,或者例程没有主动刷新并且应用程序在完成之前崩溃了。

我建议在 using() 语句之后直接放置一个日志行来断言 TransactionScope 不为空。鉴于您使用代码的方式,该代码的结果不可能返回 null,如果构造函数失败,构造函数必须抛出异常,否则您将拥有非 null 事务范围。

也许更多的代码和这个测试可能会有所帮助?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文