private Agent CreateAgentInstance(AgentRecord agentRecord) { AgentFactory agentFactory = this.settings.AgentFactories[agentRecord.Id]; object state = (this.hostState == null) ? null : this.hostState.Clone(); Agent agent; try { agent = agentFactory.CreateAgent(agentRecord.Type, state); } catch (LocalizedException ex) { MExDiagnostics.EventLog.LogEvent(EdgeExtensibilityEventLogConstants.Tuple_MExAgentInstanceCreationFailure, null, new object[] { agentRecord.Name, ex.Message }); throw; } if (agent == null || agent.Id != null) { string error = (agent == null) ? "agent instance cannot be null" : "agent instance already in use"; ApplicationException ex2 = new ApplicationException(MExRuntimeStrings.AgentCreationFailure(agentRecord.Name, error)); MExDiagnostics.EventLog.LogEvent(EdgeExtensibilityEventLogConstants.Tuple_MExAgentInstanceCreationFailure, null, new object[] { agentRecord.Name, ex2.Message }); throw ex2; } agent.Id = agent.GetHashCode().ToString(CultureInfo.InvariantCulture); agent.Name = agentRecord.Name; agent.SnapshotEnabled = this.settings.MonitoringOptions.MessageSnapshotEnabled; agent.HostState = state; ExTraceGlobals.DispatchTracer.Information <string, string>((long)this.GetHashCode(), this.InstanceNameFormatted + "agent '{0}' created from factory '{1}'", agent.GetType().FullName, agentFactory.GetType().FullName); return(agent); }