我想在另一个 AppDomain 中调用加载程序集,并在该程序集中调用一些函数。
它适用于 C# 代码:
AppDomain otherDomain0 = AppDomain.CreateDomain("otherDomain");
otherDomain0.DoCallBack(new CrossAppDomainDelegate(MyCallBack));
static public void MyCallBack(){ }
虽然它不在 powershell 中:
$domain = [AppDomain]::CreateDomain("foo")
$domain.DoCallback({ Write-Host “get called” })
异常(exception):
Exception calling "DoCallBack" with "1" argument(s): "Cannot serialize delegates over unmanaged function pointers, dynamic methods or methods outside the delegate creator's assembly." At line:1 char:1 + $domain.DoCallback({ + ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : SerializationException
我的 powershell 版本是 5.0.10586.672。
我错过了什么吗?
据此post @jame-ko 可以让它工作。
最佳答案
“基于错误,它不起作用。当您使用脚本 block 作为委托(delegate)时,Powershell 会创建动态方法。”
这是我从 powershell 专家那里得到的回复。
关于.net - Powershell 中的 AppDomain.DoCallBack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40982175/