Easy to fix issue between NServiceBus and Code Contracts

If you use NServiceBus' Configure.With fluent interface, and you use Code Contracts in any assem­blies that your NServiceBus config­u­ration uses, then configure Code Contracts in those assem­blies not to build separate code contract assem­blies, because this confuses NServiceBus.

Configure.With scans all assem­blies for imple­men­ta­tions, and if any imple­men­tation you have also generates code contract assem­blies, then basi­cally you will end up with 2 assem­blies that expose the same classes — one with the actual imple­men­tation, the other with the code contracts. This confuses NServiceBus and you'll get an error:

There is a component already registered for the given key

The simple solution is to go to the "offending" assembly project's Properties, select the Code Contracts tab, and in the Contract Reference Assembly drop­downlist, select "(none)" instead of "Build". The contract code will then be compiled straight into the code assembly rather than sepa­rately, and this will fix the issue with NServiceBus.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

1 Comment

  1. Steve Degosserie Said,

    June 18, 2010 @ 8:16 am

    So, how's your expe­rience with NServiceBus so far ? You should blog about it :-)