After changing version of visualstudio2022buildtools
from 117.8.3.0 to 117.13.1 and installing dotnet-9.0-sdk the following script started to error:
Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\Microsoft.Build.dll" [Microsoft.Build.Construction.SolutionFile]::Parse('C:/Test/Test.sln')
Exception calling "Parse" with "1" argument(s): "Could not load file or assembly 'System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified." At C:\Test\run.ps1:2 char:1 + [Microsoft.Build.Construction.SolutionFile]::Parse('C:/Test/Test ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : FileNotFoundException
I tried to change 2022 in the script to 2019 and 2017 - the same error. Tried with downloaded Microsoft.Build.dll 17.11.4 and 17.13.9 - the same error. So, I assume that the culprit here is the additional version of the SDK.
I'm unclear on the exact problem, but you report that upgrading your PowerShell (Core) 7 version to 7.5.0 solved the problem.
Observations about your symptom:
Since your script tries to load a .NET assembly in-process into your PowerShell session (using Add-Type
), the .NET / .NET Framework version underlying the session matters.
The assembly version stated in the error message, 4.0.1.1
, implies that an attempt is made to load the (legacy) .NET Framework System.Memory.dll
assembly, which is located at C:\WINDOWS\System32\WindowsPowerShell\v1.0\system.memory.DLL
, which I would expect to be the case if you run your script from Windows PowerShell (the legacy, ships-with-Windows, Windows-only edition of PowerShell whose latest and last version is 5.1), given that it builds on the legacy, Windows-only .NET Framework.
By contrast, PowerShell (Core) 7 builds on .NET, the modern, cross-platform successor to .NET Framework, and the current stable version as of this writing, v7.5.0, builds on and comes bundled with .NET 9.0.1; the current preview version, v7.6.0-preview.3, builds on .NET 9.0.2, which matches the .NET SDK reference in your screenshot.