我有一个可以在我的开发 PC(VS2013 和 Window 8.1 Enterprise x64)上完美运行的 Web 角色,但是当我将其发布到 Azure 时失败,但出现以下异常:
[InvalidProgramException: Common Language Runtime detected an invalid program.]
Castle.Core.ComponentModel.get_Dependencies() +0
Castle.Core.ComponentModel.AddConstructor(ConstructorCandidate constructor) +264
Castle.MicroKernel.ModelBuilder.Inspectors.ConstructorDependenciesModelInspector.ProcessModel(IKernel kernel, ComponentModel model) +535
Castle.MicroKernel.ModelBuilder.<>c__DisplayClass6.<BuildModel>b__4(IContributeComponentModelConstruction c) +137
System.Collections.Generic.List`1.ForEach(Action`1 action) +95
Castle.MicroKernel.ModelBuilder.DefaultComponentModelBuilder.BuildModel(IComponentModelDescriptor[] customContributors) +404
Castle.MicroKernel.Registration.ComponentRegistration`1.Castle.MicroKernel.Registration.IRegistration.Register(IKernelInternal kernel) +283
Castle.MicroKernel.DefaultKernel.Register(IRegistration[] registrations) +198
Castle.Facilities.TypedFactory.TypedFactoryFacility.InitFacility() +745
Castle.Facilities.TypedFactory.TypedFactoryFacility.Init() +78
Castle.MicroKernel.Facilities.AbstractFacility.Castle.MicroKernel.IFacility.Init(IKernel kernel, IConfiguration facilityConfig) +165
Castle.MicroKernel.DefaultKernel.AddFacility(String key, IFacility facility) +507
Castle.MicroKernel.DefaultKernel.AddFacility(IFacility facility) +213
Castle.MicroKernel.DefaultKernel.AddFacility() +167
Castle.Windsor.WindsorContainer.AddFacility() +138
PingTree.Journey.WebRole.IoCConfig.RegisterComponents() in d:\Users\Ben\OneDrive\Source\PingTree\JourneyWebRole\PingTree.Journey.WebRole\App_Start\IoCConfig.cs:19
PingTree.Journey.WebRole.MvcApplication.Application_Start() in d:\Users\Ben\OneDrive\Source\PingTree\JourneyWebRole\PingTree.Journey.WebRole\Global.asax.cs:15
[HttpException (0x80004005): Common Language Runtime detected an invalid program.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +475
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +214
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +203
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +313
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +250
[HttpException (0x80004005): Common Language Runtime detected an invalid program.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +452
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +99
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +1017
RegisterComponents 方法的代码是
public static void RegisterComponents()
{
var assemblyPath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "bin");
var windsorContainer = new WindsorContainer();
windsorContainer.AddFacility<TypedFactoryFacility>();
windsorContainer.Install(FromAssembly.InDirectory(new AssemblyFilter(assemblyPath)));
windsorContainer.Register(Classes.FromThisAssembly().BasedOn<IController>().LifestyleTransient());
ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(windsorContainer));
}
它在 windsorContainer.AddFacility 方法调用上失败。
我已经尝试了通常的方法,使用 NuGet 从项目中删除 Castle.Windsor,删除本地副本并重新安装 Windsor。此处的另一个答案建议删除本地临时 ASP.Net 文件,我也尝试过。但是每次我发布我都会遇到同样的问题。
更新 1 我已经能够使用样板 azure web 角色模板和以下代码重现问题
protected void Application_Start()
{
var windsorContainer = new WindsorContainer();
windsorContainer.AddFacility<TypedFactoryFacility>();
}
有人在天蓝色上使用 Castle Windsor 3.3 没有问题吗?