2

我正在使用事务性 NTFS 读取和写入文件系统上的文件,并且我注意到应用程序遇到间歇性故障,这只能通过重新启动应用程序来解决。错误的堆栈跟踪是:

System.Runtime.InteropServices.COMException (0xD0190052): Exception from HRESULT: 0xD0190052
   at ...KtmTransactionHandle.IKernelTransaction.GetHandle(IntPtr& handle)
   at ...KtmTransactionHandle.CreateKtmTransactionHandle(Transaction managedTransaction)
   at ...KtmTransactionHandle.CreateKtmTransactionHandle()
   at ...TransactedFile.Open(String path, FileMode mode, FileAccess access, FileShare share)
   at ...TransactedFile.ReadAllText(String path)

IKernelTransaction 是一个 COM 接口,我可以使用它来处理:

    [ComImport]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    [Guid("79427A2B-F895-40e0-BE79-B57DC82ED231")]
    private interface IKernelTransaction
    {
        void GetHandle([Out] out IntPtr handle);
    }

这里

IKernelTransaction tx = (IKernelTransaction)TransactionInterop.GetDtcTransaction(Transaction.Current);

我的代码与http://msdn.microsoft.com/en-us/library/cc303707.aspx非常相似

问题是我找不到此 COM 错误 0xD0190052 的任何信息。只要知道这个错误代码是什么就会有很大帮助。

谢谢

4

1 回答 1

1

纯猜测
HRESULT 0xD0190052 与 STATUS_TRANSACTIONMANAGER_NOT_ONLINE 非常相似,即 0xC0190052 ......不同之处在于“N”位表示代码是否为所谓的 NTSTATUS(参见http://msdn.microsoft.com/en -us/library/0642cb2f-2075-4469-918c-4441e69c548a%28PROT.10%29.aspxhttp://msdn.microsoft.com/en-us/library/cc231200%28v=PROT.10%29.aspxhttp://msdn.microsoft.com/en-us/library/cc704588%28v=PROT.10%29.aspx )...

从您的描述看来,您的应用程序有时会失去与事务管理器的连接,或者事务管理器不稳定/重新启动或类似......

还定义PreserveSig(true)您的 COM 导入可以帮助获得一些HRESULT描述......

希望这对你的情况有任何意义......

编辑:

我不确定您链接到的代码是否考虑了所有可能性...在该方法TransactedFile.Open中有一个scope.Complete();很好且必要的调用但是如果在 using-block 中此调用之前的某些代码抛出一些异常它不会根据http://msdn.microsoft.com/en-us/library/ms172152.aspx被调用这是不好的

于 2011-07-26T15:50:32.243 回答