I'm rewriting a small PowerShell application I made several months ago. This application creates a NotifyIcon. Previously I was loading the icon (image) by pointing the script at the image file. Now I'd like to embed the image code directly using Base64 code.
This works perfectly on a Windows 7 and Windows Server 2012R2 machine, but it fails on Windows 10 (updated).
Here is the command that fails and the returned error :
New-Object System.Windows.Media.Imaging.BitmapImageERROR: New-Object : Cannot find type [System.Windows.Media.Imaging.BitmapImage]: verify that the assembly containing this type is loaded.
The PowerShell version on the Windows 10 machine, were the command fails :
PSVersion : 5.1.14393.187
The PowerShell version on the Windows Server 2012 R2, were the command runs :
PSVersion : 4.0
Anyone knows how to make it work on the Windows 10 computer, or how to load the required assembly in the PowerShell session ?
1 Answer
BitmapImage uses the PresentationCore assembly.
Load the assembly: Add-Type -AssemblyName PresentationCore.
After loading, you should be able to see a list of members with [System.Windows.Media.Imaging.BitmapImage] | Get-Member. If you tried this before the assembly was loaded, you would receive a TypeNotFound error.
Now you can create the New-Object.