NSB messagehandler registered twice

in a test suite using NServicebus with AspNetCore.Mvc.Testing, a test suddenly failed if I loaded the main Assembly with Assembly.LoadFile

It seems like NSB is registering the handler twice in the container

Can you spot the problem?

Hi, did some further testing. The bug has nothing to do with MS MVC testing framework. I isolated the bug to be triggered by this single file

Hi @Stig_Christensen

I’ve looked at the NsbBugTesting project. The reason why the handler is loaded twice is that the NsbBug assembly is loaded twice. First due to reference between the NsbBugTesting project, and the second time when you call Assembly.LoadFile - which allows loading an assembly with the same identity multiple times.


Yes I also found this on stackoverflow

But shouldn’t NSB be error tolerant here?

What NServiceBus is doing is that it scans all the loaded modules and searches for types that are handlers. This is the reason why, in your scenario, a handler type is found twice.