问题描述
我使用的是定制对象生成器(Autofac),所以我可以重新使用多种类型的,我在一个共同的组件都做了登记。当我运行的服务,在NServiceBus.Host.exe主持,我得到以下错误:
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是未处理的:
SerializationException was unhandled:
在组装型Autofac.Core.Registration.ComponentNotRegisteredException'Autofac,版本= 3.0.0.0,文化=中性公钥= 17863af14b0044da'未标记为可序列化。
Type 'Autofac.Core.Registration.ComponentNotRegisteredException' in assembly 'Autofac, Version=3.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da' is not marked as serializable.
这似乎很奇怪,我是因为NServiceBus使用Autofac在默认情况下并没有同样的问题。
This seems odd to me because NServiceBus uses Autofac by default and doesn't have this same issue.
我使用Autofac v 3.1.1和4.0.3 NServiceBus
I am using Autofac v 3.1.1 and NServiceBus 4.0.3
推荐答案
这是真实的, ComponentNotRegisteredException
未标记为可序列 - 便携式类库不支持 SerializableAttribute
和Autofac 3.0+是PCL。
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.
我猜你正在运行到更大的问题不是 SerializationException
这么多的问题,导致它 - 这东西在你的自定义code没有注册,所以当某些类型得到解决它不能建立,因此,Autofac抛出了 ComponentNotRegisteredException
和NServiceBus试图序列化。
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.
,我就开始看 ComponentNotRegisteredException
的来源,专注于这一点。
Instead of trying to solve the serialization problem, I'd start looking at the source of the ComponentNotRegisteredException
and focus on that.
这篇关于NServiceBus IoC的序列化异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!