Why does machine.config contain invalid Xml content after installing .Net 3.5 patches?

For quite a few times, I heard customers would hit this issue after installing .Net 3.5 patches or repair 3.5 on Windows Vista or Windows 2008 Server. Basically the machine.config file contains some invalid Xml content and applications using configuration do not work, especially for IIS-hosted applications. The main problem is that the WCF 3.5 installer (WFServiceReg.exe) did not handle the different cases very well.

Problem Statement

There are three different cases that I have heard:

Issue 1: .Net 3.0 is removed but .Net 3.5 is on the box

On Windows Vista and Windows 2008 Server, .Net 3.0 is installed through Component-Based Setup (CBS). However, .Net 3.5 is installed through Windows Installer (MSI). Thus .Net 3.5 does not have a strong dependency on .Net 3.0. People could accidentally uninstall .Net 3.0 from the box. This would cause the section handlers (for <system.serviceModel> etc) for WCF removed from machine.config. However, any further .Net 3.5 patch would cause the WCF installer to run and it would install the following dangling elements into machine.config:









This would cause the application to fail with the following error:

System.Configuration.ConfigurationErrorsException: Unrecognized configuration section system.serviceModel. (c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Config\machine.config line 146)

Issue 2: .Net 3.0 is on the box but the WCF section handlers are removed

For some unknown reason, .Net 3.0 is not uninstalled from the machine. However, the WCF section handlers are accidentally removed when different orders of install/uninstall operations happened. The application would also fail with the same error as Issue 1 above.

Issue 3: Redundant Xml elements when configSource is used

The WCF 3.5 installer does not recognize “configSource” attribute of <client/> or <extensions/> elements and still add more Xml content when it runs.

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: A section using ‘configSource’ may contain no other attributes or elements.
Source Error:

Line 173:                 <client configSource=”client.config”>

Line 174:      <metadata>

Line 175:        <policyImporters>

Source File: C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\machine.config    Line: 174


Here are two different solutions that would help to resolve the above issues:

Solution 1: Repair .Net 3.0

For issues 1 and 2, you can repair .Net 3.0 on the machine. Here are the rough steps on Windows 2008 Server:

·        Start -> Control Panel

·        Programs -> Turn Windows features on or off -> Features

·        Check “.Net Framework 3.0” component to uninstall and reinstall it

Solution 2: Run WFServicesReg.exe Tool

For issues 1 and 2, you can run the WFServicesReg.exe tool (on the box) to fix the problem:

1)     For Issue 1, i.e., .Net 3.0 is not installed (“C:\windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe” does not exist), run the following:

%windir%\Microsoft.NET\Framework\v3.5\WFServicesReg.exe /r /b

2)     For Issue 2, i.e.,  .Net 3.0 is installed (“C:\windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe” exists), run the following:

%windir%\Microsoft.NET\Framework\v3.5\WFServicesReg.exe /r /b

“%windir%\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe” /i

%windir%\Microsoft.NET\Framework\v3.5\WFServicesReg.exe /c /b

Solution 3: Run attached javascript file

The above solutions do not fix the Issue 3. So I created a javascript FixServiceModel30Reg.js to fix the problem. You can run it as following to fix all of the above issues. Steps:

·        Download the script FixServiceModel30Reg.txt and save it to the root of c: drive.

·        Rename it to FixServiceModel30Reg.js.

·        Open the Command Prompt window and run the following command:

Cscript.exe c:\FixServiceModel30Reg.js


Comments (12)

  1. Tom McClelland says:

    A huge huge thank you for this.

    We are a .NET 2.0 user with about 10,000 sites running our winforms application.

    3 of those sites rang us up with this problem yesterday after the latest round of MS updates, and we've just fixed the first one using your .js file. I expect that we'll get more in the coming days.

  2. Tom McClelland says:

    Just fixed another one. It is worth noting that on Vista or Windows 7 when firing up the Command Prompt window you'll need to select the "Run as Administrator" option, or you're forbidden to alter the .NET configuration file. We guessed this would be the case, but some readers might not.

  3. Jeff says:

    Hurray! Thanks again! Completely in the dark on what could have been the issue. Ran your script and worked perfect.

  4. Jirka says:

    Thanks a lot, solution 2 did not function but script yes.

  5. Innocent says:

    Thanks, thanks and thanks again for your script. You need to see the downtime this has caused my company. Your script saved the day. The world really needs people like you.

  6. Aaron says:

    The script also fixed this issue in relation to the active directory web services service not starting after patching.

  7. Hamzeh says:

    Guys i tried to run the script, but it does do anything. it just gives:

    C:>cscript FixServiceModel30Reg.js

    Microsoft (R) Windows Script Host Version 5.7

    Copyright (C) Microsoft Corporation. All rights reserved.

    And thats it.

    Please help.

  8. Huzzah says:

    Thanks for the solution!  It worked!  Resolution 1 and 2 failed for me with strange errors despite having the proper versions of .Net.  Used your script and the issue is resolved.  It looks like that script took some work.  Thank you for taking the time to create it and post it!  Resolution 3 works!

  9. Florian Ev. says:

    Thanks for the solution no. 3

    It works for Windows Server 2003 SP2 x64 and MS Exchange 2007 SP1

  10. John says:

    I found I needed to add a call to Main(); at the bottom of the provided js file for this to run using cscript.

  11. Brian Klish says:

    "I found I needed to add a call to Main(); at the bottom of the provided js file for this to run using cscript."

    -me too.  it worked once I did that

  12. Lew Berry says:

    Just used script to fix an issue caused by failed Win10 upgrade that breaks iastoricon and some other things that call .net 2.0 machine.config (C:WindowsMicrosoft.NETFramework64v2.0.50727Configmachine.config) and end up failing

    Configuration system failed to initialize

    Root element is missing