4

我有一个可以在我的开发 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 没有问题吗?

4

3 回答 3

4

更具体的答案是这似乎是 IntelliTrace 的问题。引发无效程序异常的部署启用了 IntelliTrace。通过禁用 IntelliTrace 并重新部署解决方案,角色初始化并正确启动。

于 2014-07-14T21:52:31.477 回答
0

我们确实有同样的问题,我们也使用温莎城堡 3.3。我们也从 azure 发布配置文件中删除了 intelliTrace,它神奇地解决了这个问题。

于 2014-08-29T15:51:25.553 回答
0

我仍然不确定是什么导致了 InvalidProgramException。但是,我能够通过删除 Azure 部署并创建一个全新的 Visual Studio 解决方案并发布它来解决我的问题。

于 2014-07-08T11:08:20.103 回答