0
我在ASP .NET 4 MVC應用程序中使用Castle Windsor 3.1.0,當調用container.Register時,它在Application_Start事件中給了我一個例外。Castle Windsor Dynamic Assembly Bug?
異常是「被調用的成員在動態程序集中不受支持」。這裏的堆棧跟蹤:
[NotSupportedException: The invoked member is not supported in a dynamic assembly.]
System.Reflection.Emit.InternalAssemblyBuilder.GetExportedTypes() +56
Castle.Core.Internal.ReflectionUtil.GetAvailableTypes(Assembly assembly, Boolean includeNonExported) in c:\BuildAgent\work\5b096cace0fecb1f\src\Castle.Windsor\Core\Internal\ReflectionUtil.cs:165
Castle.MicroKernel.Registration.FromAssemblyDescriptor.<SelectedTypes>b__0(Assembly a) in c:\BuildAgent\work\5b096cace0fecb1f\src\Castle.Windsor\MicroKernel\Registration\FromAssemblyDescriptor.cs:56
System.Linq.<SelectManyIterator>d__14`2.MoveNext() +238
Castle.MicroKernel.Registration.FromDescriptor.Castle.MicroKernel.Registration.IRegistration.Register(IKernelInternal kernel) in c:\BuildAgent\work\5b096cace0fecb1f\src\Castle.Windsor\MicroKernel\Registration\FromDescriptor.cs:160
Castle.MicroKernel.Registration.BasedOnDescriptor.Castle.MicroKernel.Registration.IRegistration.Register(IKernelInternal kernel) in c:\BuildAgent\work\5b096cace0fecb1f\src\Castle.Windsor\MicroKernel\Registration\BasedOnDescriptor.cs:530
Castle.MicroKernel.DefaultKernel.Register(IRegistration[] registrations) in c:\BuildAgent\work\5b096cace0fecb1f\src\Castle.Windsor\MicroKernel\DefaultKernel.cs:506
Castle.Windsor.WindsorContainer.Register(IRegistration[] registrations) in c:\BuildAgent\work\5b096cace0fecb1f\src\Castle.Windsor\Windsor\WindsorContainer.cs:483
ProductX.Web.Windsor.Installers.ControllerInstaller.Install(IWindsorContainer container, IConfigurationStore store) in C:\TeamProjects\CompanyX.ProductX\Mainline\Admin\ProductX.Web\Windsor\Installers\ControllerInstaller.cs:24
Castle.Windsor.Installer.AssemblyInstaller.Install(IWindsorContainer container, IConfigurationStore store) in c:\BuildAgent\work\5b096cace0fecb1f\src\Castle.Windsor\Windsor\Installer\AssemblyInstaller.cs:56
Castle.Windsor.WindsorContainer.Install(IWindsorInstaller[] installers, DefaultComponentInstaller scope) in c:\BuildAgent\work\5b096cace0fecb1f\src\Castle.Windsor\Windsor\WindsorContainer.cs:319
Castle.Windsor.WindsorContainer.Install(IWindsorInstaller[] installers) in c:\BuildAgent\work\5b096cace0fecb1f\src\Castle.Windsor\Windsor\WindsorContainer.cs:452
ProductX.Web.MvcApplication.InitializeWindsor() in C:\TeamProjects\CompanyX.ProductX\Mainline\Admin\ProductX.Web\Global.asax.cs:41
ProductX.Web.MvcApplication.Application_Start() in C:\TeamProjects\CompanyX.ProductX\Mainline\Admin\ProductX.Web\Global.asax.cs:25
[HttpException (0x80004005): The invoked member is not supported in a dynamic assembly.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9171773
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +131
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +194
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +339
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +253
[HttpException (0x80004005): The invoked member is not supported in a dynamic assembly.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9090876
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256
這裏是我如何打電話註冊:
container.Register(Classes.FromThisAssembly().BasedOn<IController>().LifestyleTransient());
當我建立在調試模式下的應用程序,它的罰款。當我在Release模式下構建時,上面的例外發生。我無法通過Google找到有關此錯誤的任何信息。我懷疑是因爲動態程序集的反射方式引入了一些.NET 4限制,因此在這種情況下將其引入到發佈版本優化中。
任何想法的人?
謝謝帕特里克,它幫助我更進一步。如果我在該位置使用Where(),我不能再使用BasedOn(),因爲它標記爲Obsolete並重置查詢。如果我先使用BasedOn,然後使用Where(),則它會說Where()已過時並將重置查詢。很混亂...... –
它確實解決了動態組裝問題,所以我會將問題標記爲已回答。謝謝。 –
您可能想要進行一些反射並遍歷AppDomain中加載的所有程序集,以找出創建動態程序集的內容。動態程序集的名稱應該像「ahsbzfd」(即隨機字符)一樣突出。看看那個大會,看看裏面有什麼。 – PatrickSteele