1

I'm trying to mix C# and VB.Net in my project. However I'm getting an error. I already put this lines of codes in my web.config unfortunately still I'm getting an error;

<compilation debug="true">
    <codeSubDirectories>
      <add directoryName="VB" />
      <add directoryName="CSharp" />
    </codeSubDirectories>
  </compilation>
  
<system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs"
                type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
                type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
    </compilers>
</system.codedom>
  

Here's the error that I'm getting;

enter image description here

I already look into these posts, here, here, here, and here. But still I'm getting an error. How to fix this? Thank you.

EDIT Whole web.config

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.6.1">
      <codeSubDirectories>
        <add directoryName="VB" />
        <add directoryName="CSharp" />
      </codeSubDirectories>
    </compilation>
    <httpRuntime targetFramework="4.6.1"/>
    <httpModules>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
    </httpModules>
  </system.web>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
    </compilers>
  </system.codedom>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules>
      <remove name="ApplicationInsightsWebTracking"/>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
        preCondition="managedHandler"/>
    </modules>
  </system.webServer>
</configuration>
Rich
  • 3,928
  • 4
  • 37
  • 66

2 Answers2

2

There is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' section defined message will appear if you're trying to run a .NET 3.5 project in .NET 4.x application pool, since machine.config of .NET 4.x already has scriptResourceHandler section (you can check in %Windir%\Microsoft.NET\Framework\v4.0.30319\Config\machine.config):

<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
    <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">

        <!-- this section causing duplicate error for .NET 3.5 projects -->
        <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
        ...
    </sectionGroup>
</sectionGroup>

Also if you're checking web.config in the same directory as machine.config, the ScriptResourceHandler is already registered there:

<httpHandlers>
    ...

    <!-- this handler is already registered in .NET 4.x default web.config -->
    <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="False"/>

    ...
</httpHandlers>

FYI, I found that configSections element on .NET 3.5 projects has scriptResourceHandler section like this:

<configSections>
    <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
        <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
        <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" />
          <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
          <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
          <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
        </sectionGroup>
      </sectionGroup>
   </sectionGroup>
</configSections>

Try remove duplicated scriptResourceHandler section in configSections marked with version 3.5.0.0 above and try to build again, or if you don't want to upgrade the project just change IIS application pool to use version 2.0 instead.

NB: I tried to create a new MVC project from template in VS 2010 using .NET 3.5 and found that both C# & VB are available as compiler language="c#;cs;csharp" & compiler language="vb;vbs;visualbasic;vbscript".

References:

MSDN Blog: There is a duplicate scriptResourceHandler section defined

IIS7 deployment - duplicate 'system.web.extensions/scripting/scriptResourceHandler' section

Tetsuya Yamamoto
  • 24,297
  • 8
  • 39
  • 61
  • You're right, I doubled the tag and its already registered if that's what it means. Now, it's working. Thank you! – Rich Jul 10 '17 at 05:16
0

Pay attention to your error message. You can run C# and VB in the same project:

enter image description here

As the error message states:

There is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' section defined. The issue is because your are running a .net 3.5-based application in Net 4.0

The reason you are having the error is your full web.config, which I requested you post in full, has section definitions that are already included in the root web.config in .NET 4.0 default .config (see %windir%\microsoft.net\framework\v4.0.30319\config\machine.config)

Alexander Higgins
  • 6,765
  • 1
  • 23
  • 41
  • I don't know what it means in _The issue is because your are running a .net 3.5-based application in Net 4.0_ yet, I'm using 4.6.1 framework. Do the **duplicate** saying I have a duplication of tag or something? – Rich Jul 10 '17 at 03:18