I don't understand the NewNotImplementedException runtime error I'm getting
Asked Answered
C

2

7

I'm trying to implement a remote runspace that needs both connectionInfo to talk to Exchange and an imported module to talk to active directory. Here is problem code:

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

The runtime error I get is:

Cannot perform operation because operation "NewNotImplementedException at offset 32 in file:line:column :0:0" is not implemented

If I omit the runspaceInitialSessionState line I don't get the error but the PowerShell command SetADServerSettings to ViewEntireForest fails to run because it's not recognized.

StackTrace:

Cannot perform operation because operation "NewNotImplementedException at offset 32 in file:line:column :0:0 " is not implemented. at System.Management.Automation.RemoteRunspace.get_InitialSessionState() at ManageUserForwardsWS.ManageUserForwards.SetExchangeCredentials(String userName, String PwString) in c:\Users\rtanner.CATNET\Documents\Visual Studio 2013\Projects\ManageUserForwardsWS\ManageUserForwardsWS\ManageUserForwards.asmx.cs:line 122

I can also generate the same error with this code instead:

        Pipeline pipeline = runspace.CreatePipeline();

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

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

And here's the StackTrace:

Cannot perform operation because operation "NewNotImplementedException at offset 32 in file:line:column :0:0" is not implemented. at System.Management.Automation.RemoteRunspace.get_InitialSessionState() at ManageUserForwardsWS.ManageUserForwards.SetForward(String sAMAccountName, String fowardAddress) in c:\Users\rtanner.CATNET\Documents\Visual Studio 2013\Projects\ManageUserForwardsWS\ManageUserForwardsWS\ManageUserForwards.asmx.cs:line 151

Does this added information help? Any ideas on how to fix this?

Chose answered 7/1, 2014 at 18:17 Comment(5)
Do you mind adding the stack trace for that error? It may give some insight.Becoming
Line 122 (see stack trace) is the ImportPSModule() line.Chose
Welcome to SO, Rob. +1 to your question, for showing good effort. Your previous comment though, should really be edited in to the question, since it might help others to help you and you don't want it to be hidden down in the comments.Dorina
It may be an error on your ActiveDirectory module, or an auto-generated method that automatically implemented the NotImplementedException. Check this thread out: #13929792Becoming
Yes, I think you are right and I'm going to have my Windows Administrator check it for me. From within a MD shell, I typed powershell to get into a powershell command shell. in the shell, I types the command: import-module ActiveDirectory and that worked fine and then Set-AdServerSettings -ViewEntireForest $True. the response that came back was basically that it didn't recognize it as the name of a cmdlet, script, or executable program. And that is wrong since that cmdlet is in the ActiveDirectory module.Chose
H
1

As far as I can read in Microsoft documention Set-AdServerSettings is not part of ActiveDirectory module but is an Exchange CmdLet.

Using Exchange Management Shell Commands With Managed Code article show the code you have to write to use Set-AdServerSettings CmdLet in C#.

Hairline answered 8/1, 2014 at 5:16 Comment(1)
It may be in both but I've used it before in ActiveDirectory. The problem however, is that the failure is in importing the module. The code fails before it ever gets to the Set-AdServerSettings cmdlet. There is another way I can generate an error on PSImport, but it's a different error and I've updated my original post to include it.Chose
M
0

Remote Runspace constructor doesn't initialize and use InitialSessionState object. It works only with Local runspaces.

Muslin answered 30/7, 2019 at 18:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.