M Brain
M Brain

Reputation: 1

Exchange Transport Agent failed to create from assembly

I wrote a smtp receive transport agent for an on premise exchange 2016 server. here is the code

using Microsoft.Exchange.Data.Common;
using Microsoft.Exchange.Data.Transport;
using Microsoft.Exchange.Data.Transport.Smtp;

namespace AKMTransportAgent
{
    public sealed class Class1 : SmtpReceiveAgentFactory
    {
        public override SmtpReceiveAgent CreateAgent(SmtpServer server)
        {
            return new MyAgent();
        }
    }

    public class MyAgent : SmtpReceiveAgent
    {
        public MyAgent()
        {
            this.OnEndOfData += new EndOfDataEventHandler(MyEndOfDataHandler);
        }

        private void MyEndOfDataHandler(ReceiveMessageEventSource source, EndOfDataEventArgs e)
        {

            if (e.MailItem?.Message != null)
            {
                foreach (var recipient in e.MailItem.Recipients)
                {
                    if(null == recipient) { continue; }

                    string addr = recipient.Address.GetAddress(false);

                    if (addr == "[email protected]")
                    {
                        e.MailItem.Message.Subject += " - this text appended by transport agent";
                        break;
                    }
                }
            }
        }
    }
}

I copied the files

Microsoft.Exchange.Data.Common.dll
Microsoft.Exchange.Data.Transport.dll
AKMTransportAgent.dll

to

C:\Program Files\Microsoft\Exchange Server\V15\TransportAgents\AKMTransportAgent

I installed the agent using the exchange managment shell

Install-TransportAgent -Name "AKMTransportAgent" -TransportAgentFactory "AKMTransportAgent.Clas
s1" -AssemblyPath "C:\Program Files\Microsoft\Exchange Server\V15\TransportAgents\AKMTransportAgent\AKMTransportAgent.dl
l"

Enable-TransportAgent -Identity "AKMTransportAgent"

then i restarted the "Microsoft Exchange Transport" service and checked the status

[PS] C:\Windows\system32>get-transportagent

Identity                                           Enabled         Priority
--------                                           -------         --------
Transport Rule Agent                               True            1
DLP Policy Agent                                   True            2
Retention Policy Agent                             True            3
Supervisory Review Agent                           True            4
Malware Agent                                      True            5
Text Messaging Routing Agent                       True            6
Text Messaging Delivery Agent                      True            7
System Probe Drop Smtp Agent                       True            8
System Probe Drop Routing Agent                    True            9
Exchange DkimSigner                                True            10
AKMTransportAgent                                  True            11

I sent an email and found this 2 errors in the event viewer

Failed to create agent factory for the agent 'AKMTransportAgent' with error 'Failed to create type 'AKMTransportAgent.Class1' from assembly 'C:\Program Files\Microsoft\Exchange Server\V15\TransportAgents\AKMTransportAgent\AKMTransportAgent.dll' due to error 'Invalid agent assembly path.'.'. Please verify the corresponding transport agent assembly and dependencies with correct version are installed.

and

Microsoft Exchange couldn't start transport agents. The Microsoft Exchange Transport service will be stopped. Exception details: Failed to create type 'AKMTransportAgent.Class1' from assembly 'C:\Program Files\Microsoft\Exchange Server\V15\TransportAgents\AKMTransportAgent\AKMTransportAgent.dll' due to error 'Invalid agent assembly path.'. : Microsoft.Exchange.Data.ExchangeConfigurationException: Failed to create type 'AKMTransportAgent.Class1' from assembly 'C:\Program Files\Microsoft\Exchange Server\V15\TransportAgents\AKMTransportAgent\AKMTransportAgent.dll' due to error 'Invalid agent assembly path.'. ---> System.ArgumentException: Invalid agent assembly path.
   --- End of inner exception stack trace ---
   at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.FactoryTable.CreateAgentFactory(AgentInfo agentInfo)
   at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.FactoryTable..ctor(IEnumerable agents, FactoryInitializer factoryInitializer)
   at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.FactoryTable.CreateDefaultFactoryTable(IEnumerable agents, FactoryInitializer factoryInitializer)
   at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.RuntimeSettings..ctor(IMExConfiguration config, String agentGroup, FactoryInitializer factoryInitializer, IAgentGrayExceptionHandler agentGrayExceptionHandler, IExecutionStatisticsCollectorFactory statisticCollectorFactory, ITransportComponentConfiguration settingsConfiguration)
   at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.RuntimeSettingsFactory.CreateDefaultRuntimeSettings(IMExConfiguration config, String agentGroup, FactoryInitializer factoryInitializer, IAgentGrayExceptionHandler agentGrayExceptionHandler, IExecutionStatisticsCollectorFactory statisticCollectorFactory, ITransportComponentConfiguration settingsConfiguration)
   at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.RuntimeSettingsFactory.Create(IMExConfiguration config, String agentGroup, FactoryInitializer factoryInitializer, IAgentGrayExceptionHandler agentGrayExceptionHandler, IExecutionStatisticsCollectorFactory statisticCollectorFactory, ITransportComponentConfiguration settingsConfiguration)
   at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.MExRuntime..ctor(String configFile, String agentGroup, ProcessTransportRole processTransportRole, IAgentGrayExceptionHandler agentGrayExceptionHandler, IExecutionStatisticsCollectorFactory statisticCollectorFactory, FactoryInitializer factoryInitializer, ITransportComponentConfiguration transportComponentConfiguration)
   at Microsoft.Exchange.Transport.Extensibility.AgentComponent.Load()

Upvotes: 0

Views: 59

Answers (0)

Related Questions