/// <summary> /// Execute method. /// </summary> internal T ExecuteMethod <T>(RemoteHostMethodId methodId, object[] parameters) { Dbg.Assert(parameters != null, "Expected parameters != null"); // Create the method call object. long callId = _serverDispatchTable.CreateNewCallId(); RemoteHostCall remoteHostCall = new RemoteHostCall(callId, methodId, parameters); RemoteDataObject <PSObject> dataToBeSent = RemoteDataObject <PSObject> .CreateFrom(RemotingDestination.Client, _remoteHostCallDataType, _clientRunspacePoolId, _clientPowerShellId, remoteHostCall.Encode()); // report that execution is pending host response _transportManager.SendDataToClient(dataToBeSent, false, true); // Wait for response. RemoteHostResponse remoteHostResponse = _serverDispatchTable.GetResponse(callId, null); // Null means that the response PSObject was not received and there was an error. if (remoteHostResponse == null) { throw RemoteHostExceptions.NewRemoteHostCallFailedException(methodId); } // Process the response. object returnValue = remoteHostResponse.SimulateExecution(); Dbg.Assert(returnValue is T, "Expected returnValue is T"); return((T)remoteHostResponse.SimulateExecution()); }