0

私はMicrosoft.Diagnostics.Runtimenugetパッケージを使用しています。これは、スタックトレースを取得しようとする私のコードです:

var pid = Process.GetCurrentProcess().Id;
// Line of error
using (var dataTarget = DataTarget.AttachToProcess(pid, 5000, AttachFlag.Invasive))
{
    ClrInfo currentRuntime = dataTarget.ClrVersions[0];
    var runtime = currentRuntime.CreateRuntime();
    foreach (var t in runtime.Threads)
    {
        MessageBox.Show("Got here");
        t.StackTrace
    }
}

質問はClrMD で自分自身にアタッチしますか? に似ています。HRESULT: 0x80070057しかし、さらに一歩進んで、Wix を使用してアプリケーションをビルドします。次に、アプリケーションをデスクトップにインストールして、Visual Studio とそのデバッガーなしで実行できるようにします。

行の後に置く限り、メッセージボックスは表示されませんusing (var dataTarget = DataTarget.AttachToProcess(pid, 5000, AttachFlag.Invasive))。メッセージボックスを前に置くと、メッセージボックスが表示されます。

コードでは、エラーが発生します

Microsoft.Diagnostics.Runtime.ClrDiagnosticsException: 'Could not attach to pid 624, HRESULT: 0x80070057'

デバッグ中のため Visual Studio でアプリケーションを実行すると動作しない理由は理解できたと思いAttachFlag.Invasiveますが、Wix でビルドしてデスクトップにインストールした後にその行が動作しない理由がわかりません。

繰り返しますが、添付の Stackoverflow の投稿AttachFlag.Invasiveと同様に、機能AttachFlag.NonInvasiveしませんが、AttachFlag.Passive機能します。

4

1 に答える 1