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