Compiler executable file csc.exe cannot be found in .NET 4.5 Azure deployment
Asked Answered
H

5

10

I have a site which was and works:

  • ASP.NET 4
  • MVC 3
  • Entity Framework 4.3
  • Running in an Azure web role (i noticed it was osFamily="1" which is weird as I expected it to be 2 - but anyway...)
  • Azure SDK 1.7

I have upgraded my entire codebase to be up to date with the plethora of new toys. So now it is:

  • ASP.NET 4.5
  • MVC 4 (Razor 2)
  • Entity Framework 5
  • Azure config set to osFamily="3"
  • Azure SDK 1.8 (with Storage Client Library painstakingly upgraded to 2 not 1.7)

When I access the site in staging I get a yellow screen of death saying Compiler executable file csc.exe cannot be found. My question is Why?

It works fine locally, in Release mode too. I remoted in and the instances are definitely running Windows Server 2012 (therefore .NET 4.5?? I've seen it's hard to tell since .NET 4.5 replaces .NET 4 assemblies in the .NET 4 folders).

According to the response headers it is definitely running IIS 8 but interesting it claims X-ASPNET-VERSION is 4.xxxx. Is this normal for a ASP.NET 4 site?

UPDATE:

I targeted the .NET 4 framework and changed the osFamily to 2 and it now works. So I now suspect that I have a 3rd party assembly that uses .NET 3.5 or 2 (infact I'm certain I do) but surely when targeting a .NET framework higher than ones referenced in imported assemblies the higher version of the framework is used??

osFamily="3" only has .NET 4 and 4.5 installed so I guess this is the reason for the error but am I not right about the targeting thing? I want to use osFamily="3" what can I do here?

Stack trace

[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
Harrington answered 12/11, 2012 at 11:58 Comment(0)
H
1

Okay David Ebbo pointed me in the right direction and I started scrutinising Entity Framework Profiler. There is a thread here about it.

Something about it creating an assembly at run time and it would seem osfamily="3" (Server 2012) wont allow that (it worked on osfamily="2" (Server 2008 R2)). Not going to debug anymore than that since I don't want the profiler on my live environment anyway. Removing EF Profiler made it work.

Harrington answered 15/1, 2013 at 20:47 Comment(0)
V
4

I had similar issue. Make sure that you are targeting correct compiler. I was targeting v4.5 (but there shoul be v4.0 as there is now 4.5 compiler)

In web.config check

<system.web>
 <compilation debug="true" defaultLanguage="c#" optimizeCompilations="true" targetFramework="4.0">
</system.web>
Vibrations answered 31/3, 2014 at 18:10 Comment(0)
V
2

Yes, if you have Server 2012, you're definitely running Fx 4.5 and not 4.0, as it's an in place upgrade.

To answer your question in bold, a given ASP.NET app can only use one framework at a time. If you're running as a 4.5 site, then any 2.0/3.5 assemblies should just run as is under framework 4.5.

So my suspicion is that those older assemblies are not the root of your problem.

That being said, I can't explain the csc issue. It might help to include the exact error message that you're getting as well as some of the stack trace.

Villainy answered 14/1, 2013 at 18:48 Comment(3)
Thanks David. Okay my suspicions are correct about the .NET version but now I'm running out of ideas. I've added the Stack Trace as asked. I notice Hibernating Rhinos stuff so wonder if it is to do with EF Prof. I can't see why but I can try getting rid of itHarrington
Ah yes, the stack is interesting as we see csc is not being launched by ASP.NET but by HibernatingRhinos. And I see you found a thread on their forum relating this this. Thanks for the bounty points :)Villainy
David Ebbo! You Save me! I've also HibernatingRhinos that generate me this error! Thank You!Triune
H
1

Okay David Ebbo pointed me in the right direction and I started scrutinising Entity Framework Profiler. There is a thread here about it.

Something about it creating an assembly at run time and it would seem osfamily="3" (Server 2012) wont allow that (it worked on osfamily="2" (Server 2008 R2)). Not going to debug anymore than that since I don't want the profiler on my live environment anyway. Removing EF Profiler made it work.

Harrington answered 15/1, 2013 at 20:47 Comment(0)
U
0

I'm posting this in the hope that it helps someone. We were dynamically compiling code with the version 2 of the framework and on a .net 4 only server we got the error message. It was simply because we hard coded the framework version:

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

So it was just a matter of removing that - presumably so it compiles with whatever version of the framework is in use at the time.

var provider = new CSharpCodeProvider();

So the error is just about code needing to be compiled but the compiler for the required framework version is not present. The other option was just to make sure .net 3.5 feature is installed.

Underproof answered 26/3, 2017 at 23:31 Comment(0)
S
0

I had a similar issue with an AWS windows server 2019 image.

The CSharpCodeProvider was set to .Net version 2.0 for compatibility reasons:

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

I've installed the ASP 4.7 feature, my app worked fine except for this issue.
It turns out that .Net 2.0 wasn't installed on the machine.

Solution - Install the .Net 3.5 feature from the Windows server management console.
.Net 3.5 comes with .Net 2.0

Spielman answered 5/10, 2020 at 18:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.