Recently, I wanted to access the System.Windows.Forms.Integration.ElementHost type, which uses the System.Windows.Forms.Integration namespace.
When I tried to load that namespace, PowerShell complained that The assembly ‘System.Windows.Forms.Integration’ could not be found.
I read up and found that the WindowsFormsIntegration.dll would need to be loaded, and I begrudgingly added this to my script:
# This needs to be manual for some reason $netpath = [System.Reflection.Assembly]::GetExecutingAssembly().ImageRuntimeVersion $wpforms = "$env:SystemRoot\Microsoft.NET\Framework\$netpath\WPF\WindowsFormsIntegration.dll" [System.Reflection.Assembly]::LoadFile($wpforms) | Out-Null
It’s ugly though, and I wondered if there was another way. Then I thought maybe I can just add the base name of the DLL file, and sure enough, this works!
Add-Type -AssemblyName WindowsFormsIntegration
So the next time that you see an assembly can’t be found can be loaded by using the DLL, try just the DLL name instead!