andy
andy

Reputation: 8885

Can't test NServicebus Message Handlers with Messages which implement generics

I'm using:

I'm using the nservicebus.Testing namespace which nservicebus provides for testing IMessage handlers.

My tests throw this error when invoking the IMessage handler:

System.InvalidOperationException : Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true.

This error goes away and the tests run fine if I remove a reference in the test project to an assembly which contains IMessages which implement generics.

NOTE that the Handler I'm testing is not handling the generics messages, the mere presence of the generics message in the bin folder is causing the error.

I would like however to be able to test handlers for IMessages which implement generics, is this possible?

cheers

Upvotes: 1

Views: 935

Answers (1)

Udi Dahan
Udi Dahan

Reputation: 12057

The issue is that the NServiceBus testing library makes use of the same assembly type scanning logic as NServiceBus in general. In order to prevent scanning the problematic assembly, call Test.Initialize(params Assembly[] assemblies);

All that being said, it isn't recommended to have messages that make use of generics.

Upvotes: 1

Related Questions