Click here to Skip to main content
14,388,816 members
Rate this:
Please Sign up or sign in to vote.
Dear all i have problem with WCF Service.

Administration WPF project (exe) is trying to read config file one of WCF service (Read AppSettings).
Application works properly, successfully read and write App.config file while in debug mode (as VS host Services automatically (Service host environment)), but when i deploy services on IIS, I face bellow exception.

Here is detail description of Exception

exePath must be specified when not running inside a stand alone exe.
Type: System.ArgumentException:
Stack Trace: at System.Configuration.ConfigurationManager.OpenExeConfigurationImpl(ConfigurationFileMap fileMap, Boolean isMachine, ConfigurationUserLevel userLevel, String exePath, Boolean preLoad)
at Business.XXXService.AdminService.ReadEmailConfiguration(GenericRequest`1 request) in E:\Source\MB Services\Source Code\Source Code\Business\NFS.Business.COSService\ServicesImpl\AdminService.cs:line 388

As I understand, In development mode, there is aap.config file for services (WCF Service library project), but when going to deploy on IIS, configuration read from Web.config
So I implemented both cases.
Here is implementation of reading config file, But still face issue on deployed Service.

Configuration configuration = null;

               if (HttpContext.Current != null)
                   configuration = WebConfigurationManager.OpenWebConfiguration("~");
                   configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

               if (configuration == null)
                   response.Status.Code = ReturnCode.DataNotFound.GetStringValue();
                   response.Status.Message = "Unable to read configuration";
                   return response;


I think there is no need to investigate in app/web.config therefore I am not attaching config File

Thanks in Advance
Updated 23-May-18 23:46pm
Rate this:
Please Sign up or sign in to vote.

Solution 1

M.Kamran Asim 5-Jun-13 5:33am
Thanks dude!
If you see question, I already implement this approach, but still issue, as HttpContext.Current is always null, if you have not enabled AspnetCompatibality.
So thats the point where Service was trying to read second option, and failed.
I have posted solution, please go through,

Thanks for your support.
I saw that solution also while searching, but thought this might help you better.

Anyway, good work, well done.
Rate this:
Please Sign up or sign in to vote.

Solution 3


If you don't can or want to enable asp compability just check WebOperationContext.Current != null instead of HttpContext.Current.

It's located in System.ServiceModel.Web.

Rate this:
Please Sign up or sign in to vote.

Solution 2

Dear All,

Issue Solved.

You need to enable asp compatibility bellow steps can solve such issue.

set AspnetCompatibilityEnabled true in web.config ServiceModel Node (If you are using WCF service library then add AspnetCompatibilityEnabled in ServiceModel Node in aap.config)

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />

Second you need to Add AspNetCompatibilityRequirements Attribute to compatible service with

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class AdminService : IAdminService

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100