Fixing PlatformNotSupportedException when running Window Communication Foundation applications
A few days ago when attempting to run a custom Windows Communication Foundation (WCF) application on a customer’s server, I encountered the following infamous error message:
System.PlatformNotSupportedException: Operation is not supported on this platform. at System.Net.SystemWebProxy.GetProxy(Uri destination)
Usually when this problem happens with WCF applications, it indicates that the ServiceHost cannot be started. Particularly, the exception is thrown when the following code is called:
ServiceHost host = new ServiceHost(typeof(MyWCFService)); host.Open();
As usual, the first course of action is to check if the port the ServiceHost binds to is available. If possible, try again with a different port. After that, check that the app is being run on an account with administrative rights and that there is no antivirus software or firewalls blocking the port. Also check that the Windows Process Activation Service and WCF Activation features are installed on the machine:
From Control Panel > Administrative Tools > Services, check that the Windows Process Activation Service is indeed running:
In my experience, the above steps will fix the problem most of the times, since the issue is typically due to lack of administrator rights and/or missing WCF components on the machine. If the error message still persists, like what happened for my case, it is because ServiceHost is not able to load the HTTP system driver (http.sys) required to run a HTTP listener from .NET apps, likely because the driver is missing or has been disabled.
On Windows 7 and Windows Server 2008, in Device Manager, there is a category named ‘Non-Plug and Play Drivers‘ showing http.sys and various other system drivers. This category is by default hidden and can only be shown by selecting View > Show hidden devices:
Open the Properties dialog for the HTTP driver and you will most likely see that its Startup type has been set to Disabled. To fix the PlatformNotSupportedException issue, change it to Demand and restart the machine:
On Windows 8 and Windows Server 2012, Device Manager will no longer show non plug-and-play entries, even if you choose to show hidden devices. To set the startup type, go to the registry branch HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP and check the DWORD value for key Start. A value of 4 means that the driver has been disabled. To configure the HTTP driver to load on demand, set Start to 3 and reboot the machine. Your WCF application should now be able to open ServiceHost with no issues.