1

I am using a "custom" object builder (Autofac) so I can re-use the registration of many types that I have done in a common assembly. When I run the service, hosted within NServiceBus.Host.exe, I get the following error:

SerializationException was unhandled:

Type 'Autofac.Core.Registration.ComponentNotRegisteredException' in assembly 'Autofac, Version=3.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da' is not marked as serializable.

This seems odd to me because NServiceBus uses Autofac by default and doesn't have this same issue.

I am using Autofac v 3.1.1 and NServiceBus 4.0.3

Flea
  • 1,490
  • 2
  • 19
  • 43
  • Are you using multiple `AppDomains`? Exceptions are serialized across boundaries, so this could be why the failure appears to be due to missing serialization attribute. However, I agree with @Travis-illig, the underlying issue is likely to do with a missing registration. – Chris Bednarski Aug 27 '13 at 08:06

3 Answers3

3

It's true that the ComponentNotRegisteredException is not marked serializable - Portable Class Libraries don't support the SerializableAttribute and Autofac 3.0+ is a PCL.

I'm guessing the larger issue you're running into isn't the SerializationException so much as the problem causing it - that something in your custom code isn't registered, so when some type is getting resolved it can't be built and, thus, Autofac throws that ComponentNotRegisteredException and NServiceBus is trying to serialize it.

Instead of trying to solve the serialization problem, I'd start looking at the source of the ComponentNotRegisteredException and focus on that.

Travis Illig
  • 23,195
  • 2
  • 62
  • 85
  • I am going to look into this and continue investigating. – Flea Aug 26 '13 at 20:23
  • As it turns out it wasn't one of my dependencies that weren't being registered properly; it was one of NServiceBus' (when it was registering a singleton). I was able to better implement my wrapper of that method and it's now working. Thanks for the suggestion. As well, John Simmons' answer was very helpful in leading toward resolving the issue. I'd like to give his answer credit too but can pick only one. – Flea Aug 30 '13 at 14:57
2

The simplest way to diagnose these kind of issues is to turn on break on all exception in Visual Studio and see where it booms out first time.
9/10 is a problem with the initialization code.

John Simons
  • 4,288
  • 23
  • 41
  • 1
    The problem comes when it does not occur in dev but only in production, at customers. Debugging is than replaced by guessing since there's no sensible information that comes out of the exception. – Alexey Zimarev Mar 21 '14 at 14:33
0

I ran into a similar error while adding NServiceBus.Distributor.Msmq (4.4.2) to an old solution using NServiceBus 4.4.2. Turned out I'd forgotten to set up the NSB license for the new project. Trying to start the distributor threw this until I included a valid License.xml file in the build output:

Unhandled Exception: System.Runtime.Serialization.SerializationException: Type 'Autofac.Core.DependencyResolutionException' in assembly 'NServiceBus.Core, Version=4.4.0.0, Culture=neutral PublicKeyToken=9fc386479f8a226c' is not marked as serializable.

mandersen
  • 13
  • 1
  • 5