ASP.NET部署IIS后出现System.InvalidCastException异常求助
ASP.NET 发布至IIS后出现InvalidCastException异常的解决方法
给ASP.NET应用添加resx语言包后,调试阶段构建正常,且可顺利切换语言,但发布至IIS服务器后出现以下异常:
Server Error in '/' Application Unable to cast object of type 'System.Web.Compilation.BuildResultCompiledAssembly' to type 'System.Web.Compilation.BuildResultCompiledGlobalAsaxType' Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Web.Compilation.BuildResultCompiledAssembly' to type 'System.Web.Compilation.BuildResultCompiledGlobalAsaxType' Source Error An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below Stack Trace [InvalidCastException: Unable to cast object of type 'System.Web.Compilation.BuildResultCompiledAssembly' to type 'System.Web.Compilation.BuildResultCompiledGlobalAsaxType'.] System.Web.Compilation.ApplicationBuildProvider.GetGlobalAsaxBuildResult(Boolean isPrecompiledApp) +448 System.Web.Compilation.BuildManager.CompileGlobalAsax() +47 System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +336 [HttpException (0x80004005): Unable to cast object of type 'System.Web.Compilation.BuildResultCompiledAssembly' to type 'System.Web.Compilation.BuildResultCompiledGlobalAsaxType'.] System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +76 System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +607 System.Web.Compilation.BuildManager.CallAppInitializeMethod() +33 System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +865 [HttpException (0x80004005): Unable to cast object of type 'System.Web.Compilation.BuildResultCompiledAssembly' to type 'System.Web.Compilation.BuildResultCompiledGlobalAsaxType'.] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +532 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +111 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +724 Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4690.
该异常刷新几次后会消失,但通常一天后会再次出现。尝试清理并重建应用、使用全新的bin文件夹,均未解决问题。
更新:经排查,问题由AssemblyInfo.cs中的[assembly: AssemblyCulture("en-ZA")]代码行导致,注释该行后问题解决。
内容的提问来源于stack exchange,提问作者Moshe Malatji
相关产品推荐
相关产品推荐

