在我的引导程序中,我首先这样做:
public static void Initialise()
{
var container = BuildUnityContainer();
InitializeNServiceBus(container);
DependencyResolver.SetResolver(new UnityDependencyResolver(container));
...
}
而InitializeNServiceBus的内容是这样的:
private static void InitializeNServiceBus(IUnityContainer container)
{
var typesToScan = new [] {
typeof (RequestPasswordResetCommand),
typeof (CreateAccountCommand)
};
Configure.With(typesToScan)
.DefineEndpointName("somequeueonmysystem")
.UnityBuilder(container)
.XmlSerializer()
//.MsmqSubscriptionStorage()
.DisableRavenInstall()
.DisableSecondLevelRetries() //we need timeout manager for this
.DisableTimeoutManager() //we need raven db or similar for this //.RunTimeoutManager()
.MsmqTransport()
.IsTransactional(false)
.PurgeOnStartup(false)
.MsmqSubscriptionStorage()
.IsTransactional(true)
.UnicastBus()
.ImpersonateSender(false)
.SendOnly();
//.CreateBus()
// .Start(() => Configure.Instance.ForInstallationOn<NServiceBus.Installation.Environments.Windows>().Install());
}
但是,当我打开我的 MVC 应用程序时,我得到:
静态属性需要空实例,非静态属性需要非空实例。参数名称:表达式
这里指出了错误的来源:
Line 82:
Line 83: Configure.With(typesToScan)
Line 84: .DefineEndpointName("InCityS.Events.UI.Nuvonet")
Line 85: .UnityBuilder(container)
堆栈跟踪:
[ArgumentException: Static property requires null instance, non-static property requires non-null instance.
Parameter name: expression]
System.Linq.Expressions.Expression.Property(Expression expression, PropertyInfo property) +4114402
NServiceBus.Utils.Reflection.DelegateFactory.Create(PropertyInfo property) in c:\TeamCity\buildAgent\work\nsb.master_2\src\utils\NServiceBus.Utils.Reflection\DelegateFactory.cs:91
NServiceBus.Serializers.XML.XmlMessageSerializer.InitType(Type t) in c:\TeamCity\buildAgent\work\nsb.master_2\src\impl\Serializers\NServiceBus.Serializers.XML\XmlMessageSerializer.cs:133
NServiceBus.Serializers.XML.XmlMessageSerializer.InitType(Type t) in c:\TeamCity\buildAgent\work\nsb.master_2\src\impl\Serializers\NServiceBus.Serializers.XML\XmlMessageSerializer.cs:138
NServiceBus.Serializers.XML.XmlMessageSerializer.Initialize(IEnumerable`1 types) in c:\TeamCity\buildAgent\work\nsb.master_2\src\impl\Serializers\NServiceBus.Serializers.XML\XmlMessageSerializer.cs:948
NServiceBus.Serializers.XML.Config.MessageTypesInitializer.Run() in c:\TeamCity\buildAgent\work\nsb.master_2\src\impl\Serializers\NServiceBus.Serializers.XML.Config\MessageTypesInitializer.cs:20
NServiceBus.Configure.<Initialize>b__d(IWantToRunWhenConfigurationIsComplete o) in c:\TeamCity\buildAgent\work\nsb.master_2\src\config\NServiceBus.Config\Configure.cs:305
System.Collections.Generic.List`1.ForEach(Action`1 action) +10722241
NServiceBus.Configure.Initialize() in c:\TeamCity\buildAgent\work\nsb.master_2\src\config\NServiceBus.Config\Configure.cs:304
NServiceBus.Configure.SendOnly() in c:\TeamCity\buildAgent\work\nsb.master_2\src\config\NServiceBus.Config\Configure.cs:364
InCityS.UI.Open.Bootstrapper.InitializeNServiceBus(IUnityContainer container) in d:\Data_nobackup\Projects\InCityS\trunk\UI\InCityS.UI.Open\Bootstrapper.cs:83
InCityS.UI.Open.Bootstrapper.Initialise() in d:\Data_nobackup\Projects\InCityS\trunk\UI\InCityS.UI.Open\Bootstrapper.cs:53
InCityS.UI.Open.MvcApplication.Application_Start() in d:\Data_nobackup\Projects\InCityS\trunk\UI\InCityS.UI.Open\Global.asax.cs:79
[HttpException (0x80004005): Static property requires null instance, non-static property requires non-null instance.
Parameter name: expression]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9859725
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
[HttpException (0x80004005): Static property requires null instance, non-static property requires non-null instance.
Parameter name: expression]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9873912
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
当我将 typesToScan 更改为
var typesToScan = new Type[]{};
该应用程序再次运行,但是当然,一旦我尝试将某些东西放在总线上,它就会失败,说它不知道通过扫描类型的类型。
任何人都知道在哪里查看或有此错误的经验?