将解决方案更新到nServiceBus 5后,Message Mapper抛出TypeLoadException

时间:2014-12-08 11:02:51

标签: xml serialization nservicebus

我们正在将项目从NSB v3升级到NSB v5,并且遇到MessageMapper问题。适用于NSB 3的类现在正在使用NSB 5抛出类型加载的异常。

例外是:

Method 'DeepCopy' in type 'Benefex.Core.Interfaces.DTO.IUserContext__impl' from assembly 'Benefex.Commands.Operations.Batches__impl, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.

堆栈跟踪是:

at System.Reflection.Emit.TypeBuilder.TermCreateClass(RuntimeModule module, Int32 tk, ObjectHandleOnStack type)
at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
at System.Reflection.Emit.TypeBuilder.CreateType()
at NServiceBus.MessageInterfaces.MessageMapper.Reflection.MessageMapper.CreateTypeFrom(Type t, ModuleBuilder moduleBuilder)
at NServiceBus.MessageInterfaces.MessageMapper.Reflection.MessageMapper.GenerateImplementationFor(Type interfaceType, ModuleBuilder moduleBuilder)
at NServiceBus.MessageInterfaces.MessageMapper.Reflection.MessageMapper.InitType(Type t, ModuleBuilder moduleBuilder)
at NServiceBus.MessageInterfaces.MessageMapper.Reflection.MessageMapper.InitType(Type t, ModuleBuilder moduleBuilder)
at NServiceBus.MessageInterfaces.MessageMapper.Reflection.MessageMapper.Initialize(IEnumerable`1 types)
at NServiceBus.Serializers.XML.Config.MessageTypesInitializer.Run(Configure config)
at NServiceBus.Configure.Initialize()
at NServiceBus.Bus.Create(BusConfiguration configuration)
at Benefex.Core.Processor.ProcessorConfiguration.Customize(BusConfiguration configuration) in c:\TFS\Benefex\Work Streams\SignIn\Benefex.Core.Processor\ProcessorConfiguration.cs:line 33
at Benefex.P1Processor.MessageEndpoint.Customize(BusConfiguration configuration) in c:\TFS\Benefex\Work Streams\SignIn\P1Processor\Server.cs:line 12
at NServiceBus.GenericHost.PerformConfiguration(Action`1 moreConfiguration)
at NServiceBus.GenericHost.Start()
at NServiceBus.Hosting.Windows.WindowsHost.Start()
at NServiceBus.Hosting.Windows.Program.<>c__DisplayClasse.<Main>b__6(WindowsHost service)
at Topshelf.Internal.ControllerDelegates`1.StartActionObject(Object obj)
at Topshelf.Internal.IsolatedServiceControllerWrapper`1.<>c__DisplayClass2.<set_StartAction>b__1(TService service)
at Topshelf.Internal.ServiceController`1.<.cctor>b__1(ServiceController`1 sc)
at Magnum.StateMachine.LambdaAction`1.Execute(T instance, Event event, Object parameter)
at Magnum.StateMachine.EventActionList`1.Execute(T stateMachine, Event event, Object parameter)   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at NServiceBus.Hosting.Windows.Program.Main(String[] args)

IUserContent接口有一个实现类UserContext,它实现了异常中声明的方法。 IUserContext在不同的项目中定义,其实现在另一个单独的项目中。虽然我们将来可能会改变这些,但我希望NSB 5能够在不改变它们的情况下工作。

我们没有使用XML序列化(而是使用自定义JSON),但我没有找到任何方法来覆盖消息映射器,即使它似乎是XML序列化过程的一部分。

编辑 - 我设法让一个小测试项目抛出同样的错误:

using NServiceBus.Features;
using NServiceBus.Persistence;
using Raven.Client.Document;
using NServiceBus;

namespace ServiceBus
{
    public class EndpointConfig : IConfigureThisEndpoint
    {
        public void Customize(BusConfiguration configuration)
        {
            var documentStore = new DocumentStore
            {
                ConnectionStringName = "NServiceBus.Persistence"
            };

            configuration.AssembliesToScan(AllAssemblies.Except("ABCpdf9-32.dll"));

            configuration.EndpointName("testqueue");

            configuration.DisableFeature<AutoSubscribe>();
            configuration.DisableFeature<SecondLevelRetries>();

            configuration.UsePersistence<RavenDBPersistence>()
                         .SetDefaultDocumentStore(documentStore);

            var conventionsBuilder = configuration.Conventions();

            conventionsBuilder.DefiningCommandsAs(t => t.Namespace != null &&
                                                       !t.IsInterface &&
                                                       t.Name.EndsWith("Command"));
            conventionsBuilder.DefiningMessagesAs(t => t.Namespace != null &&
                                                       !t.IsInterface &&
                                                       t.Name.EndsWith("Notification"));

            Bus.Create(configuration);
        }
    }

    public interface IDeepCopy<T>
    {
        T DeepCopy();
    }

    public class TestCommand
    {
        public IUserContext UserContext { get; set; }
        public string Description { get; set; }
        public int Id { get; set; }

    }

    public interface IUserContext : IDeepCopy<IUserContext>
    {
        int Id { get; set; }
        string Description { get; set; }
    }

    public class UserContext : IUserContext
    {
        public IUserContext DeepCopy()
        {
            return new UserContext
            {
                Id = Id,
                Description = Description
            };
        }

        public int Id { get; set; }
        public string Description { get; set; }
    }
}

1 个答案:

答案 0 :(得分:0)

当您序列化消息并通过网络发送消息时,您将发送可在另一端反序列化的序列化数据。使用DeepClone方法发送了什么?我说你需要脱掉你的命令。