【问题标题】:I don't understand the NewNotImplementedException runtime error I'm getting我不明白我得到的 NewNotImplementedException 运行时错误
【发布时间】:2014-01-25 13:30:19
【问题描述】:

我正在尝试实现一个远程运行空间,它既需要 connectionInfo 与 Exchange 通信,又需要一个导入模块来与 Active Directory 通信。这是问题代码:

runspace = System.Management.Automation.Runspaces.RunspaceFactory.
CreateRunspace(psConnectionInfo);
runspace.InitialSessionState.ImportPSModule(new[] { "ActiveDirectory" });
runspace.Open();

我得到的运行时错误是:

无法执行操作,因为未实现操作“NewNotImplementedException at offset 32​​ in file:line:column:0:0”

如果我省略了 runspaceInitialSessionState 行,我不会收到错误消息,但是由于无法识别到 ViewEntireForest 的 PowerShell 命令 SetADServerSettings,因此无法运行。

堆栈跟踪:

无法执行操作,因为未实现操作“NewNotImplementedException at offset 32​​ in file:line:column:0:0”。 在 System.Management.Automation.RemoteRunspace.get_InitialSessionState() 在 ManageUserForwardsWS.ManageUserForwards.SetExchangeCredentials(String userName, String PwString) 在 c:\Users\rtanner.CATNET\Documents\Visual Studio 2013\Projects\ManageUserForwardsWS\ManageUserForwardsWS\ManageUserForwards.asmx.cs:line 122

我也可以使用此代码生成相同的错误:

        Pipeline pipeline = runspace.CreatePipeline();

        PowerShell powershell = PowerShell.Create();
        powershell.Runspace = pipeline.Runspace;

        powershell.Runspace.InitialSessionState.ImportPSModule(new[] { "ActiveDirectory" });

这里是 StackTrace:

无法执行操作,因为操作“NewNotImplementedException at offset 32​​ in file:line:column:0:0”未实现。 在 System.Management.Automation.RemoteRunspace.get_InitialSessionState() 在 ManageUserForwardsWS.ManageUserForwards.SetForward(String sAMAccountName, String fowardAddress) 在 c:\Users\rtanner.CATNET\Documents\Visual Studio 2013\Projects\ManageUserForwardsWS\ManageUserForwardsWS\ManageUserForwards.asmx.cs:line 151

这些附加信息有帮助吗?有关如何解决此问题的任何想法?

【问题讨论】:

  • 您介意为该错误添加堆栈跟踪吗?它可能会提供一些见解。
  • 第 122 行(参见堆栈跟踪)是 ImportPSModule() 行。
  • 欢迎来到 SO,Rob。 +1 对您的问题,以显示良好的努力。不过,您之前的评论确实应该编辑到问题中,因为它可能会帮助其他人帮助您,并且您不希望它隐藏在 cmets 中。
  • 可能是您的 ActiveDirectory 模块出错,或者是自动生成的方法自动实现了 NotImplementedException。检查此线程:stackoverflow.com/questions/13929292/…
  • 是的,我认为您是对的,我将让我的 Windows 管理员帮我检查一下。在 MD shell 中,我输入了 powershell 以进入 powershell 命令 shell。在 shell 中,我输入命令:import-module ActiveDirectory,它运行良好,然后是Set-AdServerSettings -ViewEntireForest $True。返回的响应基本上是它没有将其识别为 cmdlet、脚本或可执行程序的名称。这是错误的,因为该 cmdlet 在 ActiveDirectory 模块中。

标签: c# powershell exchange-server runspace


【解决方案1】:

据我所知,Microsoft documention Set-AdServerSettings 不是 ActiveDirectory 模块的一部分,而是一个 Exchange CmdLet。

Using Exchange Management Shell Commands With Managed Code 文章展示了在 C# 中使用 Set-AdServerSettings CmdLet 所必须编写的代码。

【讨论】:

  • 可能两者都有,但我之前在ActiveDirectory 中使用过。然而,问题在于导入模块失败。代码在到达Set-AdServerSettings cmdlet 之前就失败了。还有另一种方法可以在 PSImport 上生成错误,但这是一个不同的错误,我已经更新了我的原始帖子以包含它。
【解决方案2】:

远程运行空间构造函数不初始化和使用 InitialSessionState 对象。 它仅适用于本地运行空间。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-26
    • 1970-01-01
    • 1970-01-01
    • 2016-10-09
    • 1970-01-01
    • 1970-01-01
    • 2021-08-02
    • 1970-01-01
    相关资源
    最近更新 更多