I am working on a C# application that uses the PowerShell class in System.Management.Automation to run PowerShell scripts remotely. In one PS1 file I have made I am using som assemblies
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
This works fine when running the script directly in PowerShell on a computer, but when running it through the application I get this error.
Error running instruction: Cannot find path 'C:WindowsSystem32System.Windows.Forms.dll' because it does not exist.
I am not sure why it is looking for the assembly dll files in that directory when running the PS file through the application.
How can I find where it find the correct dll files when executing the script locally in PowerShell?
Edit: Might the problem be that PowerShell instance invoked by the application is not using the Global Assembly Cache, and if not how can I make it use it?
question from:
https://stackoverflow.com/questions/65933982/issue-finding-assemblies-when-running-ps-scripts-with-system-management-automati 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…