Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / system

Fixing PlatformNotSupportedException when Running Window Communication Foundation Applications

0.00/5 (No votes)
7 May 2023CPOL2 min read 2.4K  
How to fix PlatformNotSupportedException when running WCF apps
This post shows how to fix PlatformNotSupportedException when you run WCF 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:

C#
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:

wcf_activation_services

From Control Panel > Administrative Tools > Services, check that the Windows Process Activation Service is indeed running:

wcf_service_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:

device_manager_http_sys_non_pnp

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:

http_driver_startup_type_demand

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)