【发布时间】:2018-07-29 04:33:59
【问题描述】:
我有一个像这样的简单 DotNet DLL
namespace ClassLibrary1
{
public class Class1
{
public static void Test()
{
Process.Start("CMD.exe", "/C calc");
}
}
}
当我尝试用 powershell 加载这个 DLL 时
$Path = "c:\\test\\ClassLibrary1.dll";
$Namespace = "ClassLibrary1";
$ClassName = "Class1";
$Method = "Test";
$Arguments = $null
$Full_Path = [System.IO.Path]::GetFullPath($Path);
$AssemblyName = [System.Reflection.AssemblyName]::GetAssemblyName($Full_Path)
$Full_Class_Name = "$Namespace.$ClassName"
$Type_Name = "$Full_Class_Name, $($AssemblyName.FullName)"
$Type = [System.Type]::GetType($Type_Name)
$MethodInfo = $Type.GetMethod($Method)
$MethodInfo.Invoke($null, $Arguments)
它不起作用,因为[System.Type]::GetType($Type_Name) 返回了$null
有什么想法吗?
【问题讨论】:
-
您没有加载程序集。
[System.Type]::GetType不会加载程序集,除非它位于 GAC 或程序集搜索路径中。 -
您可能需要使用
LoadFile:stackoverflow.com/questions/3079346/…
标签: c# powershell