"[E2010] [TA] [C#]: Error with TA after update to EX2010 SP2 - couldn't start transport agents, unable to cast object ... to ....Transport.AgentFactory RRS feed

  • Question

  • Hello, I couldn't find an answer for my problem, so I decided to ask here for help.

    We are using an simple Transport Agent, which is not working anymore since the update of EX2010 to SP2 yesterday.
    We are getting the error:
    "'Unableto cast object of type 'NSCatchEmail.MyAgentFactory' to type 'Microsoft.Exchange.Data.Transport.AgentFactory'."

    The complete Error Message is:
    Microsoft Exchange couldn't start transport agents. The Microsoft Exchange Transport service will be stopped. Exception details: Failed to create type 'NSCatchEmail.MyAgentFactory' from assembly 'C:\CatchEmail\CatchEmail.dll' due to error 'Unable to cast object of type 'NSCatchEmail.MyAgentFactory' to type 'Microsoft.Exchange.Data.Transport.AgentFactory'.'. :
    Microsoft.Exchange.Data.ExchangeConfigurationException: Failed to create type 'NSCatchEmail.MyAgentFactory' from assembly 'C:\CatchEmail\CatchEmail.dll' due
    to error 'Unable to cast object of type 'NSCatchEmail.MyAgentFactory' to type 'Microsoft.Exchange.Data.Transport.AgentFactory'.'. ---> System.InvalidCastException: Unable to cast object of type 'NSCatchEmail.MyAgentFactory' to type 'Microsoft.Exchange.Data.Transport.AgentFactory'.
    at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.FactoryTable.<>c__DisplayClass4.<CreateAgentFactory>b__3(Assembly assembly) at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.FactoryTable.LoadAssemblyAndCreateInstance[T](AgentInfo agentInfo, CreateInstance`1 createInstance, String& agentPath, Exception& exception)

    ---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)
    at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.RuntimeSettings..ctor(MExConfiguration config, String agentGroup)
    at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.MExRuntime.Initialize(String configFile, String agentGroup, Boolean isBridgeHead, String installPath)
    at Microsoft.Exchange.Transport.Categorizer.MExEvents.Initialize(String configFilePath)
    at Microsoft.Exchange.Transport.Components.CategorizerMExRuntimeLoader.Load()
    Version of agent 'CatchEmail' is not compatible with server version. The exception is 'Failed to create type 'NSCatchEmail.MyAgentFactory' from assembly 'C:\CatchEmail\CatchEmail.dll' due to error 'Unable to cast object of type 'NSCatchEmail.MyAgentFactory' to type 'Microsoft.Exchange.Data.Transport.AgentFactory'.'.' ---------------------


    <o:p>The code from the beginning of the agent, which I'm thinking causes the problem:</o:p>

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Exchange.Data.Transport;
    using Microsoft.Exchange.Data.Transport.Routing;
    using Microsoft.Exchange.Data.Transport.Smtp;
    using Microsoft.Exchange.Data.Common;
    using System.Diagnostics;
    using System.IO;
    namespace NSCatchEmail
        public sealed class MyAgentFactory : RoutingAgentFactory
            public override RoutingAgent CreateAgent(SmtpServer server)
                return new MyRoutingAgent();
        public class MyRoutingAgent : RoutingAgent
            public MyRoutingAgent()
                this.OnSubmittedMessage += new SubmittedMessageEventHandler(this.OnSubmittedMessageHandler);
            private void OnSubmittedMessageHandler(SubmittedMessageEventSource source, QueuedMessageEventArgs e)
              // My code starts here
              // I'm just adding text from the body to the subject
              // "newSubject" is my formatted text from the body
              e.MailItem.Message.Subject += " " + newSubject;

    (I got this code from

    Has anything changed in the way of writing a Transport Agent with EX2010 SP2?
    I've no idea why or where the error is caused.

    Thanks for your Help.
    Micha Krapp

    Friday, February 24, 2012 10:44 AM

All replies

  • Question:

    Do I have to renew the references in my TA to the Microsoft.Exchange.Data.Transport.dll and -.Common.dll with a new update of the EX2010?

    Because the version of the files in the Public-folder of Exchange is newer than the ones I have referenced to while developing.

    Can't try it out now, have to do that on Monday.

    Friday, February 24, 2012 2:38 PM
  • Yes the Public assembiles where updated in SP2 (the same thing happened in SP1 as well) so you need to renew those references then recompile your class library .


    Monday, February 27, 2012 1:18 AM