任何人都可以帮我解决以下问题,这似乎只发生在最新的 NServiceBus 升级(4.3 -> 4.4.2)之后。
我们正在创建一个 MVC4 应用程序,它应该接收来自其他应用程序的消息。NServiceBus 自托管在同一个应用程序中。
使用以下软件包:
- 温莎城堡 3.2.1 和城堡核心 3.2.2
- 用于整个应用程序的依赖关系解析
- NServiceBus 4.4.2
- NServiceBus CastleWindsor 4.4.2
- 合理的选择,因为我已经将 Castle 用于应用程序的其余部分
- NServiceBus SqlServer
- 出于监控原因,我们更喜欢数据库表而不是 msmq
以下代码用于初始化 NServiceBus
public class NServiceBusInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
SetLoggingLibrary.Log4Net(log4net.Config.XmlConfigurator.Configure);
Configure.Serialization.DontWrapSingleMessages();
Configure.Features.Disable<AutoSubscribe>();
Configure.Features.Disable<SecondLevelRetries>();
Configure.Features.Disable<TimeoutManager>();
Configure.ScaleOut(x => x.UseSingleBrokerQueue());
Configure.With()
.Log4Net()
.CastleWindsorBuilder(container)
.UseTransport<SqlServer>()
.DefiningMessagesAs(t => (t.Namespace == "MyNamespace.Messages") && t.Name.EndsWith("Message"))
.UnicastBus()
.LoadMessageHandlers()
.CreateBus()
.Start();
}
}
在 Global.asax Application_Start 中,此安装程序被安装在全局 windsor-container 中。
当消息到达队列时,我多次收到以下异常。以下跟踪来自组件“UnicastBus”,但我从消息传递的 NServiceBus 中的每个级别获取它。
Castle.Windsor Warning: 0 : Exception when resolving optional dependency Dependency 'MessageSender' type 'NServiceBus.Transports.ISendMessages' on component NServiceBus.Unicast.UnicastBus., Castle.MicroKernel.ComponentActivator.ComponentActivatorException: Error setting property SqlServerMessageSender.ConnectionStringCollection in component NServiceBus.Transports.SQLServer.SqlServerMessageSender. See inner exception for more information.
If you don't want Windsor to set this property you can do it by either decorating it with DoNotWireAttribute or via registration API.
Alternatively consider making the setter non-public. ---> System.NullReferenceException: De objectverwijzing is niet op een exemplaar van een object ingesteld.
bij Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.SetUpProperties(Object instance, CreationContext context)
--- Einde van intern uitzonderingsstackpad ---
bij Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.SetUpProperties(Object instance, CreationContext context)
bij Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context)
bij Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context, Burden burden)
bij Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext context, Boolean trackedExternally)
bij Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy)
bij Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden)
bij Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired)
bij Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context)
bij Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveFromKernelByType(CreationContext context, ComponentModel model, DependencyModel dependency)
bij Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveFromKernel(CreationContext context, ComponentModel model, DependencyModel dependency)
bij Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveCore(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency)
bij Castle.MicroKernel.Resolvers.DefaultDependencyResolver.Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency)
bij Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.ObtainPropertyValue(CreationContext context, PropertySet property, IDependencyResolver resolver)
最终,消息不会被转发到错误队列,并且 NServiceBus 会关闭。
在检查这个异常跟踪时,我发现 SqlServerMessageSender.ConnectionStringCollection 已经有一个私有设置器,所以我想知道为什么 Castle.Windsor 没有成功创建 MessageSender 的实例。
去完成:
网络配置包含
<connectionStrings>
<add name="NServiceBus/Transport" connectionString="myconnectionstring" providerName="System.Data.SqlClient" />
</connectionStrings>
有人知道为什么会发生此异常吗?