c# - "Common Language Runtime detected an invalid program"位于带有 CaSTLe Windsor 的 Azure Web 角色上

标签 c# asp.net azure castle-windsor invalidprogramexception

我有一个 Web 角色,可以在我的开发 PC(VS2013 和 Window 8.1 Enterprise x64)上完美运行,但当我将其发布到 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>();
    }

有人在 azure 上使用 CaSTLe Windsor 3.3 没有出现问题吗?

最佳答案

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

关于c# - "Common Language Runtime detected an invalid program"位于带有 CaSTLe Windsor 的 Azure Web 角色上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24461848/

相关文章:

c# - 带有其他参数的Unity构造函数注入(inject)

c# - 开发与web form应用一致的自定义认证授权系统

c# - 在静态类 C# ASP.NET Web 窗体中调用静态方法

Azure CDN - 使用 ETag 启用 HTTP 304 缓存 - 托管 Web 角色

azure - Azure 应用服务部署版本 4 - 找不到 *.deploy.cmd

azure - 复制 Azure Application Insights 仪表板并指向新的 Application Insights 实例

c# - 将多个连续的相等字符从一个字符串减少为一个

C# WPF Gridview 不会显示数据除非点击

asp.net - 覆盖单个页面的 ASP.NET 表单例份验证

asp.net - TryUpdateModelAsync() 无法传入对象参数进行更新