【问题标题】:Compiler executable file csc.exe cannot be found in .NET 4.5 Azure deployment在 .NET 4.5 Azure 部署中找不到编译器可执行文件 csc.exe
【发布时间】:2012-10-31 20:28:34
【问题描述】:

我有一个曾经并且可以运行的网站:

  • ASP.NET 4
  • MVC 3
  • 实体框架 4.3
  • 以 Azure 网络角色运行(我注意到它是 osFamily="1",这很奇怪,因为我预计它是 2 - 但无论如何......)
  • Azure SDK 1.7

我已经升级了我的整个代码库,以与大量新玩具保持同步。所以现在是:

  • ASP.NET 4.5
  • MVC 4(剃刀 2)
  • 实体框架 5
  • Azure 配置设置为 osFamily="3"
  • Azure SDK 1.8(存储客户端库煞费苦心地升级到 2 而不是 1.7)

当我在登台访问该站点时,我得到一个黄色的死机屏幕,提示 找不到编译器可执行文件 csc.exe。我的问题是为什么?

它在本地运行良好,在发布模式下也是如此。我进行了远程操作,并且这些实例肯定在运行 Windows Server 2012(因此 .NET 4.5??我发现这很难说,因为 .NET 4.5 替换了 .NET 4 文件夹中的 .NET 4 程序集)。

根据响应标头,它肯定在运行 IIS 8,但有趣的是它声称 X-ASPNET-VERSION 是 4.xxxx。这对于 ASP.NET 4 站点是否正常?

更新:

我以 .NET 4 框架为目标,并将 osFamily 更改为 2,它现在可以工作了。所以我现在怀疑我有一个使用 .NET 3.5 或 2 的第 3 方程序集(事实上我确信我这样做了),但是当目标 .NET 框架高于导入程序集中引用的框架时,肯定会使用更高版本的使用框架??

osFamily="3" 仅安装了 .NET 4 和 4.5,所以我想这是错误的原因,但我对目标的看法不正确吗?我想使用 osFamily="3" 我可以在这里做什么?

堆栈跟踪

[InvalidOperationException: Compiler executable file csc.exe cannot be found.]
   System.CodeDom.Compiler.RedistVersionInfo.GetCompilerPath(IDictionary`2 provOptions, String compilerExecutable) +8675071
   Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch(CompilerParameters options, String[] fileNames) +739
   Microsoft.CSharp.CSharpCodeGenerator.FromSourceBatch(CompilerParameters options, String[] sources) +3293761
   Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromSourceBatch(CompilerParameters options, String[] sources) +64
   HibernatingRhinos.Profiler.Appender.Util.GenerateAssembly.Compile(String fileName, String[] sources, IEnumerable`1 assembliesToReference) +1252
   HibernatingRhinos.Profiler.Appender.Util.GenerateAssembly.CompileAssembly(IEnumerable`1 sourcesResources, IEnumerable`1 assembliesToReference, String assemblyName) +118
   HibernatingRhinos.Profiler.Appender.EntityFramework.EntityFrameworkProfiler.SetupDatabaseDefaultConnectionFactoryIfNeeded() +929
   HibernatingRhinos.Profiler.Appender.EntityFramework.EntityFrameworkProfiler.SetupEntityFrameworkIntegration() +80
   HibernatingRhinos.Profiler.Appender.EntityFramework.EntityFrameworkProfiler.Initialize(EntityFrameworkAppenderConfiguration configuration) +47
   HibernatingRhinos.Profiler.Appender.EntityFramework.EntityFrameworkProfiler.Initialize() +73
   Web4.MvcApplication.Application_Start() +17

[HttpException (0x80004005): Compiler executable file csc.exe cannot be found.]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +12864673
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +175
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475

[HttpException (0x80004005): Compiler executable file csc.exe cannot be found.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12881540
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12722601

【问题讨论】:

    标签: asp.net asp.net-mvc azure .net-4.5 windows-server-2012


    【解决方案1】:

    我在使用 AWS Windows Server 2019 映像时遇到了类似问题。

    出于兼容性原因,CSharpCodeProvider 设置为 .Net 2.0 版:

     new CSharpCodeProvider(new Dictionary<String, String> { { "CompilerVersion", "v2.0" } });
    

    我已经安装了 ASP 4.7 功能,我的应用程序运行良好,除了这个问题。
    原来机器上没有安装.Net 2.0。

    解决方案 - 从 Windows 服务器管理控制台安装 .Net 3.5 功能。
    .Net 3.5 附带 .Net 2.0

    【讨论】:

      【解决方案2】:

      我发布这个是希望它对某人有所帮助。我们正在使用框架的版本 2 动态编译代码,并且在仅 .net 4 的服务器上我们收到了错误消息。这仅仅是因为我们对框架版本进行了硬编码:

      var provider = new CSharpCodeProvider(new Dictionary<String, String> { { "CompilerVersion", "v3.5" } });
      

      所以这只是删除它的问题 - 大概是这样它可以与当时使用的任何版本的框架一起编译。

      var provider = new CSharpCodeProvider();
      

      所以错误只是关于需要编译的代码,但所需框架版本的编译器不存在。另一个选项只是确保安装了 .net 3.5 功能。

      【讨论】:

        【解决方案3】:

        我有类似的问题。确保您的目标是正确的编译器。 我的目标是 v4.5(但应该是 v4.0,因为现在有 4.5 编译器)

        在 web.config 中检查

        <system.web>
         <compilation debug="true" defaultLanguage="c#" optimizeCompilations="true" targetFramework="4.0">
        </system.web>
        

        【讨论】:

          【解决方案4】:

          好的,David Ebbo 为我指明了正确的方向,我开始仔细研究 Entity Framework Profiler。有一个关于它的线程here

          关于它在运行时创建程序集的一些事情,似乎 osfamily="3" (Server 2012) 不允许这样做(它在 osfamily="2" (Server 2008 R2) 上工作)。不会再进行调试了,因为无论如何我都不希望在我的实时环境中使用分析器。删除 EF Profiler 使其工作。

          【讨论】:

            【解决方案5】:

            是的,如果您有 Server 2012,那么您肯定运行的是 Fx 4.5 而不是 4.0,因为它是就地升级。

            要以粗体字回答您的问题,给定的 ASP.NET 应用程序一次只能使用一个框架。如果您作为 4.5 站点运行,那么任何 2.0/3.5 程序集都应该在框架 4.5 下按原样运行。

            所以我怀疑那些旧程序集不是你的问题的根源。

            话虽如此,我无法解释 csc 问题。包含您收到的确切错误消息以及一些堆栈跟踪可能会有所帮助。

            【讨论】:

            • 谢谢大卫。好吧,我对 .NET 版本的怀疑是正确的,但现在我的想法已经不多了。我已按要求添加了堆栈跟踪。我注意到冬眠犀牛的东西,所以想知道这是否与 EF 教授有关。我不明白为什么,但我可以尝试摆脱它
            • 啊,是的,堆栈很有趣,因为我们看到 csc 不是由 ASP.NET 启动的,而是由 HibernatingRhinos 启动的。我看到你在他们的论坛上找到了一个与此相关的主题。感谢您的赏金:)
            • 大卫埃博!你救我!我也有 HibernatingRhinos 产生这个错误!谢谢!
            猜你喜欢
            • 1970-01-01
            • 2013-06-01
            • 1970-01-01
            • 1970-01-01
            • 2016-09-16
            • 2020-10-17
            • 2020-07-15
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多