在 PowerShell 中运行 dotMemory 会导致“无法附加到进程”

问题描述 投票:0回答:1

我正在尝试从命令行自动运行 dotMemory.exe 来分析多个进程。 我使用 dotMemory 独立命令行版本。

我现在遇到了有时会发生的问题。

dotMemory.exe 失败,并显示““无法附加到进程 #mynumber:确保它存在并且它是 .NET Framework 4.0+/.NET Core 3.0+/.NET 5+ 进程。””

如果我启动一个新的PowerShell实例,它工作正常,但原始的PowerShell实例无法再使用。跑多少次都没关系。我必须关闭 powershell 窗口并打开一个新窗口,它才能再次工作。

我使用的命令:

.\dotMemory-2024.1.1.exe --log-level=trace attach 14768
(14768是PID)

我也在 powershell 脚本中尝试过,但这导致了同样的问题。

$proc = New-Object System.Diagnostics.Process

$proc.StartInfo.FileName = "dotMemory-2024.1.1.exe"
$proc.StartInfo.Arguments = "--log-level=trace attach 14768"
$proc.StartInfo.UseShellExecute = $false
$proc.StartInfo.RedirectStandardInput = $true
$proc.Start()

我在 %Temp% \JetLogs\JetBrainsLog.JetBrains.2024-04-23T12-20-58.dotMemory-2024_1_1#14768.log 中找到的内容

--- EXCEPTION #1/2 [FileLoadException]
Message = “Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)”
ExceptionPath = Root.InnerException
ClassName = System.IO.FileLoadException
HResult = FUSION_E_REF_DEF_MISMATCH=80131040
Source = System.Memory
FileLoad_FileName = “System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”
FileLoad_FusionLog = “
  === Pre-bind state information ===
  LOG: DisplayName = System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
   (Fully-specified)
  LOG: Appbase = file:///C:/Users/someuser/AppData/Local/Temp/2/JetBrains/dotMemory.exe/Qudorinirexidelu
  LOG: Initial PrivatePath = NULL
  Calling assembly : System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51.
  ===
  LOG: This bind starts in default load context.
  LOG: No application configuration file found.
  LOG: Using host configuration file: 
  LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
  LOG: Post-policy reference: System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
  LOG: Attempting download of new URL file:///C:/Users/someuser/AppData/Local/Temp/2/JetBrains/dotMemory.exe/Qudorinirexidelu/System.Runtime.CompilerServices.Unsafe.DLL.
  WRN: Comparing the assembly name resulted in the mismatch: Major Version
  ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

我在日志中看到的是“Framework64 4.0.30319”。我知道 dotMemory 需要 4.7.2。是否使用了错误的 .NET 版本?

powershell dotmemory
1个回答
0
投票

我找到了真正的问题。该应用程序作为服务运行。需要以管理员身份运行 dotMemory 才能附加。

© www.soinside.com 2019 - 2024. All rights reserved.