Dela via


There is a duplicate scriptResourceHandler section defined

In this blog, I am going to point out one common error which we usually get after deploying an ASP.NET 3.5 website on the IIS Server, however we do not see this error during development i.e. in Visual Studio. Actually this issue only happens when the application pool is using .net framework 4.0 in IIS, but we will try to understand why?

Here is the screen shot which we see when this problem occurs.

clip_image001

As we can see the message is pretty much clear “There is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' section defined”, pointing out a duplicate entry in the application web.config file at this path “E:\New\TestWeb\TestWeb\web.config”. So we can easily get rid of this issue by removing the entry from the application’s web.config file.

But the question is how do we get this entry in the web.config file? and How does this work in the Visual Studio? Let’s investigate this.

Following is that same section of web.config file opened in Visual Studio from the same solution, we can see that “scriptResourceHandler” section is present there. So we simply use the Visual Studio publish feature to deploy this application content on the IIS server and the content along with web.config file simply gets x-copied on the target location during this. Following is the screen shot of one such web.config file.

clip_image002

Let’ see what this ScriptResourceHandler is.

ScriptResourceHandler class was introduced in .net framework 3.5. This is actually a HTTP handler for processing requests for script files that are embedded as resources in an assembly. Read here for more on ScriptResourceHandler.

clip_image003

Apparently, you can also find a handler entry in the httpHandlers section of the same application web.config file.

clip_image005

We know that ASP.NET framework 3.5 uses the CLR version 2.0 and that is why framework 3.5 does not have any root web.config file like version 2.0 or 4.0 have at this location

%windir%\System32\Microsoft.NET\Framework64\<version>\CONFIG\web.config

Since CLR version is same, framework 3.5 specific section tag definitions is not present in the machine.config file respective to the version 2.0. While creating the 3.5 framework website, Visual Studio does this job for us. Visual Studio adds these section tag inside <configSections> and a respective “handler” entry in the web.config file.

So after deploying the application on IIS server, if we choose .Net framework 2.0 for the application pool, it works fine without deleting any entry from the web.config because settings required for framework 3.5 website to run are added in application web.config file and they do not exist in Machine.config file for framework 2.0.

clip_image006

Now what if we are bound to use .Net Framework 4.0 (Note: If you are creating a version 4.0 website in Visual Studio from the scratch, then Visual Studio will not add the specified entries in web.config file and this issue will never happen.). This situation may occur if we are upgrading our website from 3.5 to 4.0 framework.

Let’s open the machine.config file from this path %windir%\System32\Microsoft.NET\Framework64\ v4.0.30319\Config\machine.config and search for “scriptResourceHandler”. We can see that this entry is already there, so that is why, having this entry again in application web.config results into this error.

clip_image007

Let’s also search the root web.config file from this path %windir%\System32\Microsoft.NET\Framework64\ v4.0.30319\Config\web.config and search for  “scriptResourceHandler”. We can see that handler entry is already there. (Which was added in web.config however, existence of handler entry does not make any difference here since handlers can be specified at any level of web.config files hierarchy overriding the configuration of parent web.config)

clip_image008

So since we already have the entries in machine.config file of .net framework 4.0, again adding same entry in the application specific web.config file results into this error.

 

If you want to cross check this, follow these steps.

1. Open Visual Studio 2010

2. Create a new website of of framework 4.0.

3. Open the web.config file and check for above mentioned entries. You will not find any of the those entries, here is the screen shot.

image

4. Now change the framework of the website from 4.0 to 3.5 from website Property pages.

image

5. Now open the web.config file and check for its content. You will see all those entries in the file and you will get to know that how much Visual Studio takes care of developers.

 

image

 

Hope this was helpful, please feel free to write the feedback.

Comments

  • Anonymous
    January 06, 2014
    Thank you. I have been getting this exact error and couldn't figure out what was causing it. What was confusing was that the same site worked without this error a few weeks ago, but I couldn't figure out what change caused this, since the config file itself hadn't changed. Now I know it was a change to the Application Pool settings.

  • Anonymous
    February 10, 2014
    Glad that it helped and thanks for writing the feedback! Susanna

  • Anonymous
    April 03, 2014
    This is really a good article with so detailed information...

  • Anonymous
    April 22, 2014
    Excellent Article, just saved my life getting as could not figure out why this was occuring

  • Anonymous
    April 28, 2014
    Thanks for taking the time to document this, it's one of those things that makes so much sense once you realise what's happening, but can stump you when upgrading an application after a while of not using the .NET framework

  • Anonymous
    August 14, 2014
    SOLVED.......... just replace the code between <configurations> and    <appSettings> in your web.xml file  with the following code. <configuration>  <configSections>    <sectionGroup name="businessObjects">      <sectionGroup name="crystalReports">        <section name="rptBuildProvider" type="CrystalDecisions.Shared.RptBuildProviderHandler, CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, Custom=null" />        <section name="crystalReportViewer" type="System.Configuration.NameValueSectionHandler" />      </sectionGroup>    </sectionGroup>  </configSections> nadeesh222@gmail.com

  • Anonymous
    October 09, 2014
    This helped the issue I was facing... good write up..

  • Anonymous
    October 19, 2014
    Hi , Thanks for post It really fixed  my problem

  • Anonymous
    November 06, 2014
    I didn't see this issue until I had applied MS patches in on my WS 2012 R2 Server Nov 2014. I had applied 14 patches. Looked through each kb number applied at MS site, but nothing stood out as to which could have been the cause to make this condition surface. Anyone?

  • Anonymous
    December 19, 2014
    Very good article on this error. The details in this article helped to understand the differences and fix it very quick. Looking forward for more articles in the future. Thank you! --Mahesh

  • Anonymous
    December 29, 2014
    Hello. I have the same issue and despite having understood the problem I am unable to fix it. Please help me. Get in touch. Thanks.

  • Anonymous
    January 07, 2015
    @Nikita, Solution depends on your .NET version required on IIS.

  1. Did you try changing .net framework on IIS to 2.0?
  2. If you want 4.0, manually remove those scriptHandler entries from your local web.config file. Thanks Gaurav
  • Anonymous
    March 17, 2015
    very good article. It helped me to fix this error quickly.

  • Anonymous
    April 04, 2015
    After removing all the duplicate section defined, I got another error "Configuration file is not well-formed XML" =)). How can I fix it? If I change .net framework on IIS to 2.0 it shows up another error " This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false"."

  • Anonymous
    April 11, 2015
    @HoangTho It seems you have removed some essential character while removing those sections.  Try to open your XML file in Internet Explorer and it should tell you if XML is not proper.

  • Anonymous
    April 21, 2015
    Hi,    I deleted the lines in web.config , but I am getting new error, Parser Error Parser Error Message: Unknown server tag 'tmplt:PageBody'. If I keep pool framework 2 works fine. If I change to o=pool framework 4 and remove the lines from web.config and I am getting new error.

  • Anonymous
    May 29, 2015
    Thank you so much for your valuable post!,

  • Anonymous
    July 30, 2015
    Hi, I Have error Crystal Report viewer Not Working

  • Anonymous
    August 13, 2015
    Hi Gaurav, I hope this error is not just specific to app pool with .net version as 4.0 because the same we noticed in one of our application with app pool being 2.0 too.

  • Anonymous
    August 19, 2015
    Thanks for the clarifications. It worked.

  • Anonymous
    September 22, 2015
    this solved my problem ...thanks !!!

  • Anonymous
    November 12, 2015
    The comment has been removed

  • Anonymous
    November 25, 2015
    This blog is very helpful for me thank you Arya sir

  • Anonymous
    December 01, 2015
    I had another scenario. The parent app was a SharePoint 2010 web app and the child was an MVC4 app (don't ask, wasn't me) so I couldn't just change the framework version or do anything with the parent web.config. The reason for this error in my scenario is because the parent app is .NET 2 (SharePoint 2010) and the web.config (of the SharePoint web application) specifies these sections since it's a .NET2 framework app pool. The child app (MVC4) must be .NET 4 whose web.config does not specify these sections but because it is a .NET4 app, these values exist in the machine.config (for .NET4) by default. This is as you've already stated in your article. You get the 500.19 error since it’s merging the configuration with the parent app, even though it’s specified as a separate application with a separate application pool. To resolve the issue, I had to edit the C:WindowsSystem32inetsrvconfigapplicationHost.config file. Search for the web app pool by name and add enableConfigurationOverride="false" to the definition. I've shown it complete here: This prevents inheriting values from the parent application pool/web.config and gives you the freedom to specify your own web.config values for your .NET 4 app but it must of course be running in its own app pool. <add name="MyApplicationPool" autoStart="true" managedRuntimeVersion="v4.0" enableConfigurationOverride="false"> <processModel identityType="ApplicationPoolIdentity" /> </add>

  • Anonymous
    December 30, 2015
    Thanks Rob for explaining your issue here. This was certainly new thing for me that we can stop that config merging using this attribute. Thanks again for writing up.

  • Anonymous
    July 28, 2016
    I'm late to the party here but I just ran into this problem. Thank you - understanding the origin helped me fix it.

  • Anonymous
    January 13, 2017
    The comment has been removed

  • Anonymous
    January 15, 2017
    I have Visual Studio 2008 and Windows 10 (upgrade). When I start a new website I only have the option of 3.5 framework shown. In my webs, all of them use 3.5. However recently I I am getting error message after uploading to host: "There is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' section defined " The exact error it throws is: It appears that I need to comment out some part of my web.config script but not sure which part?

    • Anonymous
      January 18, 2017
      Hi Rae,You are running into exactly same problem. You need to remove following section from your web.config file. I would suggest, please read the article carefully and then do it.Hi Rae,You are running into exactly same problem. You need to remove following section from your web.config file. I would suggest, please read the article carefully and then do it.section name="scriptResourceHandler" type.......