C
C#3mo ago
remi.nz

✅ Powershell SDK error on .Net 8

Hey, so I've been trying to invoke a powershell command using the Powershell SDK for .Net 8 but it seems to throw an error saying Windows.Web.dll wasn't found?
15 Replies
remi.nz
remi.nz3mo ago
System.IO.FileNotFoundException: 'Could not load file or assembly 'C:\Users\Administrator\source\repos\UI Prototype\UI Prototype\bin\x64\Debug\net8.0-windows\runtimes\win\lib\net8.0\Windows.Web.dll'. The system cannot find the file specified.'
System.IO.FileNotFoundException: 'Could not load file or assembly 'C:\Users\Administrator\source\repos\UI Prototype\UI Prototype\bin\x64\Debug\net8.0-windows\runtimes\win\lib\net8.0\Windows.Web.dll'. The system cannot find the file specified.'
remi.nz
remi.nz3mo ago
I have installed all the required packages
No description
remi.nz
remi.nz3mo ago
using (PowerShell script = PowerShell.Create())
{
script.AddScript("[Windows.Management.Deployment.PackageManager,Windows.Web,ContentType=WindowsRuntime]::new().FindPackages() | Where-Object { $_.IsFramework -eq $false -and $_.SignatureKind -ne 'System' } | Select-Object DisplayName, Logo, InstalledPath");
var results = script.Invoke();

foreach (var result in results)
{
string displayName = result.Properties["DisplayName"].Value.ToString();
string logo = result.Properties["Logo"].Value.ToString();
string installedPath = result.Properties["InstalledLocation"].Value.ToString();
string packageName = GetPackageName(installedPath);
string sizeInMB = GetPackageSize(installedPath);
apps.Add(new AppxPackages { DisplayName = displayName, AppIcon = logo, InstalledPath = installedPath, PackageName = packageName, PackageSize = sizeInMB });
}
}
using (PowerShell script = PowerShell.Create())
{
script.AddScript("[Windows.Management.Deployment.PackageManager,Windows.Web,ContentType=WindowsRuntime]::new().FindPackages() | Where-Object { $_.IsFramework -eq $false -and $_.SignatureKind -ne 'System' } | Select-Object DisplayName, Logo, InstalledPath");
var results = script.Invoke();

foreach (var result in results)
{
string displayName = result.Properties["DisplayName"].Value.ToString();
string logo = result.Properties["Logo"].Value.ToString();
string installedPath = result.Properties["InstalledLocation"].Value.ToString();
string packageName = GetPackageName(installedPath);
string sizeInMB = GetPackageSize(installedPath);
apps.Add(new AppxPackages { DisplayName = displayName, AppIcon = logo, InstalledPath = installedPath, PackageName = packageName, PackageSize = sizeInMB });
}
}
My Powershell Invocation
jcotton42
jcotton423mo ago
that trick to load WinRT assemblies relies on runtime features that were removed in .NET 5 iirc
remi.nz
remi.nz3mo ago
Sooo it means I can't use Powershell like that?
jcotton42
jcotton423mo ago
yes but also like, you could just use the WinRT stuff directly from C# no point in using PowerShell for this
reflectronic
reflectronic3mo ago
i agree if you are using PowerShell just to call PackageManager there is absolutely no point in doing that. the APIs are easily usable from C#
reflectronic
reflectronic3mo ago
if this is part of a script that you already have and it's complicated to untangle it will require some amount of work to use Windows.* APIs from it on .NET 8 it is still possible though i have never tried it
remi.nz
remi.nz3mo ago
Oh alright
jcotton42
jcotton423mo ago
also I'm pretty sure Windows.Web isn't even the right assembly to load for that
remi.nz
remi.nz3mo ago
Guess so too, that's why I was confused why is it throwing this error didn't find any solutions online so decided to ask here
reflectronic
reflectronic3mo ago
in this case it does not matter because all Windows.* are redirected automatically to the right place. but, yes, it is not strictly correct
remi.nz
remi.nz3mo ago
!close
Accord
Accord3mo ago
Closed!