I have a web role that works perfectly on my Development PC (VS2013 & Window 8.1 Enterprise x64), but fails when I publish it to Azure with the following exception:
[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
The code for the RegisterComponents method is
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));
}
Its failing on the windsorContainer.AddFacility method call.
I've tried the usual things, used NuGet to remove Castle.Windsor from the project, deleted the local copy and reinstalled Windsor. Another answer here suggested deleting the local temporary ASP.Net files, I've tried that as well. But every time I publish I get the same problem.
Update 1 I've been able to reproduce the problem with the boiler plate azure web role template and the following code
protected void Application_Start()
{
var windsorContainer = new WindsorContainer();
windsorContainer.AddFacility<TypedFactoryFacility>();
}
Is anybody using Castle Windsor 3.3 on azure without problems?
A more specific answer would be that it seems to be a problem with IntelliTrace. The deployments that throw the Invalid program exception, had IntelliTrace enabled. By disabling IntelliTrace and redeploying the solution, and the role initialised and started correctly.