Jaa


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:

<system.serviceModel>

  <extensions>

    ...

  </extensions>

  <client>

    ...

  </client>

</system.serviceModel>

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

Solutions

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

FixServiceModel30Reg.txt

Comments

  • Anonymous
    May 14, 2012
    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.

  • Anonymous
    May 14, 2012
    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.

  • Anonymous
    November 12, 2012
    Hurray! Thanks again! Completely in the dark on what could have been the issue. Ran your script and worked perfect.

  • Anonymous
    January 09, 2013
    Thanks a lot, solution 2 did not function but script yes.

  • Anonymous
    February 07, 2013
    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.

  • Anonymous
    April 17, 2013
    The script also fixed this issue in relation to the active directory web services service not starting after patching.

  • Anonymous
    May 25, 2013
    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.

  • Anonymous
    October 19, 2013
    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!

  • Anonymous
    January 20, 2014
    Thanks for the solution no. 3 It works for Windows Server 2003 SP2 x64 and MS Exchange 2007 SP1

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

  • Anonymous
    December 29, 2014
    "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

  • Anonymous
    November 24, 2015
    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