Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
210 views
in Technique[技术] by (71.8m points)

c# - Issue Finding Assemblies when Running PS Scripts with System.Management.Automation

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...