Strange error occurring when using wcf to run query against sql server

Solution 1:

In your web.config, in your configuration\system.serviceModel\serviceHostingEnvironment element, add a minFreeMemoryPercentageToActivateService attribute, and set it to something lower than 5, I set mine to 0, and this error went away for me.

ex:

<configuration>
  <system.serviceModel>
    <serviceHostingEnvironment ... minFreeMemoryPercentageToActivateService="0" />
  </system.serviceModel>
</configuration>

Caution via MSDN: "Specifying this attribute along with partial trust in the web.config file of a WCF service will result in a SecurityException when the service is run."

Solution 2:

One thing you could try is changing your 'mex' service path to absolute if it is not already. It worked for me once. But that could have been due to the service restarting and freeing some memory.

BrainSlug's Answer has an example of how to do this

Solution 3:

I encountered this issue when I was running my WCF service locally (localhost). I stopped the service. Closed few apps to clean my ram. and restarted it again. It started normally as earlier.
BrainSlug's Answer also worked. +1 for that. :)
Cheers!!