.net - Powershell 中的 AppDomain.DoCallBack

标签 .net powershell

我想在另一个 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/

相关文章:

c# - Selenium WebDriver 在 RemoteWebElement.Click() 上抛出 WebDriverTimeoutException

c# - 如何将图标添加到现有的 exe 文件(默认情况下没有图标)?

c# - 从 C# : Instance does not exist in the specified category 读取性能计数器

powershell - 在PowerShell中复制到剪贴板时无需换行

Powershell - 获取 WinEvent

.net - 如何允许用户通过鼠标与图形对象交互?

c# - 如何将默认 PropertyDescriptor 设置为属性?

powershell - 在 PowerShell 中一次从 CSV 运行多个搜索以复制项目

powershell - Add-AzureAccount -credential 没有像我希望的那样工作

powershell - Powershell:远程Internet连接检查