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:

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!

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!

Chrissy is a PowerShell MVP who has worked in IT for nearly 20 years, and currently serves as a Sr. Database Engineer in Belgium. Always an avid scripter, she attended the Monad session at Microsoft’s Professional Developers Conference in Los Angeles back in 2005 and has worked and played with PowerShell ever since. Chrissy is currently pursuing an MS in Systems Engineering at Regis University and helps maintain RealCajunRecipes.com in her spare time. She holds a number of certifications, including those relating to SQL Server, SuSE Linux, SharePoint and network security. She recently became co-lead of the SQL PASS PowerShell Virtual Chapter. You can follow her on Twitter at @cl.

Posted in PowerShell

Leave a Reply

Your email address will not be published. Required fields are marked *

*