PowerShell Tip: You may not need to load the DLL for that Assembly that can't be found

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:

1# This needs to be manual for some reason
2$netpath = [System.Reflection.Assembly]::GetExecutingAssembly().ImageRuntimeVersion
3$wpforms = "$env:SystemRoot\Microsoft.NET\Framework\$netpath\WPF\WindowsFormsIntegration.dll"
4[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!

1Add-Type -AssemblyName WindowsFormsIntegration

So the next time you see an assembly “can’t be found” and you know it can be loaded via its DLL, try just the DLL name instead.

Note (2025): In PowerShell 7+ on Windows, this still works when the Windows Desktop packs (WPF/WinForms) are available. On non‑Windows platforms, these assemblies aren’t present, so loading WindowsFormsIntegration will fail.