
Fixing the FileLoadException Error
If you have installed previous versions of WCF on your machine, you may get a FileLoadFoundException error when you run the ServiceModelReg tool to register a new installation. This can happen even if you have manually removed files from the previous install, but left the machine.config settings intact.
The error message you get is similar to the following.
Error: System.IO.FileLoadException: Could not load file or assembly 'System.ServiceModel, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'System.ServiceModel, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
You should note from the error message that the System.ServiceModel Version 2.0.0.0 assembly was installed by an early CTP (Customer Technology Preview) release. The current version of the System.ServiceModel assembly released is 3.0.0.0 instead. Therefore, you will encounter this issue when you want to install the official WCF release on a machine where an early CTP release of WCF was installed, but not completely uninstalled.
ServiceModelReg.exe cannot clean up prior version entries, nor can it register the new version's entries. The only workaround is to manually edit machine.config. You can locate this file at the following location.
%windir%\Microsoft.NET\Framework\v2.0.50727\config\machine.config
If you are running WCF on a 64-bit machine, you should also edit the same file at
%windir%\Microsoft.NET\Framework64\v2.0.50727\config\machine.config
Locate any XML nodes in this file that refer to “System.ServiceModel, Version=2.0.0.0”, delete them and any child nodes. Save the file and re-run ServiceModelReg.exe will resolve this problem.