How do I fix the "compilerVersion" IIS error?
Asked Answered
N

7

56

I'm getting this exception:

System.Configuration.ConfigurationErrorsException: The value for the 'compilerVersion' attribute in the provider options must be 'v4.0' or later if you are compiling for version 4.0 or later of the .NET Framework.

What should I do to resolve this?

Nerissanerita answered 23/7, 2010 at 0:6 Comment(0)
H
67

I had a similar problem and had to tell ASP.NET in configuration to use the 3.5 compiler as follows by modifying Web.config.

I've copied and pasted the following from my code. You have to change value="v3.5" to value="v4.0". The compiler type strings might also change.

<configuration>

  <!--  ... other configuraiton stuff ... -->

  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
        <providerOption name="CompilerVersion" value="v3.5"/>
        <providerOption name="WarnAsError" value="false"/>
      </compiler>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
        <providerOption name="CompilerVersion" value="v3.5"/>
        <providerOption name="OptionInfer" value="true"/>
        <providerOption name="WarnAsError" value="false"/>
      </compiler>
    </compilers>
  </system.codedom>

</configuration>

In my case the 2.0 compiler was being used instead of 3.5. I was working in an IIS 7, ASP.NET Website project.

You might glean additional insight from:

Hackbut answered 23/7, 2010 at 0:9 Comment(3)
4igi answer has the C# 4.0 answer.Prior
As a side note to "2.0 was used instead of 3.5": The solution above worked for me too in this scenario. But I finally found out WHY the wrong compiler was being used: I'm using a "Web Deployment Project" to compile the web application and it seems it doesn't understand "CodeFile=" in aspx/ascx files (and doesn't find any ".cs" files). The legacy name "CodeBehind=" works though and the "web.config"-hack above is no longer needed. *** MSVC2010, .NET 2.0 with 3.5 Code ***Solarium
Looking at John K's references, most of the compiler element options are exactly that - optional! So, I had a similar issue with C# and vb in the same website project. The VB stuff was not working, most likely due to setting incorrect version, but we wanted any and all builds of this warning type to be ignored, so I added the compiler element with only the option I wanted: nowarn. <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="1" compilerOptions="/nowarn:618,612,40000" />Cere
T
30

this should help

<configuration>
<!--  -->
<system.codedom>
 <compilers>
  <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4"
    type="Microsoft.CSharp.CSharpCodeProvider,System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
   <providerOption name="CompilerVersion" value="v4.0"/>
   <providerOption name="WarnAsError" value="false"/>
  </compiler>
 </compilers>
</system.codedom>
<!--  -->
</configuration>
Theorem answered 14/2, 2011 at 9:26 Comment(0)
C
27

In my case, I was trying to run a child application using 4.0, but the parent application needed to still use 2.0. Wrapping the compilers information in the parent web.config with a <location path="." inheritInChildApplications="false"> tag fixed it.

Parent Web.config:

<location path="." inheritInChildApplications="false">
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
        <providerOption name="CompilerVersion" value="v3.5" />
        <providerOption name="WarnAsError" value="false" />
      </compiler>
    </compilers>
  </system.codedom>
Cresset answered 1/12, 2011 at 16:27 Comment(2)
This one helped my situation. We did not have any problems with a mixed .Net versions on the server until a vendor MSI was run.Erectile
Nice...this fixed my problem (ASP.NET 4 site is child of ASP.NET 2.0)Infracostal
N
9

Remove this section from web.config

<compilation debug="true" strict="true" explicit="true"  targetFramework="4.0" />
Nerissanerita answered 23/7, 2010 at 0:9 Comment(5)
I didn't see you that you answered your own question before I finished filling mine out :)Hackbut
Yea, but yours was more complete.Nerissanerita
Also need to remove <httpRuntime targetFramework="4.5" /> in 4.5.Virescence
For me, I had a nested <assemblies> block in <compilation>. So I just removed all the attributes and ended up with <compilation><assemblies>...</assemblies></compilation>.Anglosaxon
This helped me. Thanks. I had copied a 3.5 project and changed it to 4.0, but couldn't get it to work correctly until I did this.Scurry
V
1

In my case it was a child site under the Default Website and although the default website settings were set at ASP.NET 4.0, the web.config file was set for 2.0 and 3.5. Changing the web.config file to use 4.0 fixed it. Use this for reference: ASP.NET 4 Breaking Changes

Vivienne answered 30/8, 2011 at 19:8 Comment(0)
O
1

We had accidentally copy-pasted Web.config into C:\inetpub\wwwroot. This accidentally copy-pasted Web.config had mismatching configuration and caused the compilerVersion error for us. Deleting the Web.config solved the problem for us.

Oligocene answered 13/10, 2017 at 9:43 Comment(0)
W
0

In my case, I am using an old Webform website (V 2.0), need to append a new application which is developed in MVC4.0. This same error I was facing and after many permutations and combination of the given solution, I wrapped the whole web.comfig of the parent application in the following tag

<location path="." inheritInChildApplications="false">
...... web config tags here........
</location> 
Wolfie answered 15/5, 2019 at 4:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.