title: WCF Hosted in a Windows Service Getting Security Exceptions even though it should be running in Full Trust
body: <p>We are hosting a WCF service (.NET 4.0) in a Windows Service. It works pretty well on most machines, but on some machines it throws the following exception: "Error: An error occurred creating the configuration section handler for system.serviceModel/bindings: That assembly does not allow partially trusted callers." (The full stack trace is at the bottom of this post) </p>
  
  <p>It seems that this exception is somewhat expected in partially trusted environments, but for all we know we are (or should be) running under full trust:</p>
  
  <ul>
  <li>Everything is installed on the local C:\ drive</li>
  <li>The Windows Service is running under an admin account</li>
  <li>No software restriction policies are set</li>
  <li>We have not done anything to explicitely run under medium trust</li>
  </ul>
  
  <p>And it turns out that when we remove the binding section from the app.config (and do the configuration in code) then everything works fine. It is just reading that configuration section that is causing the issue. </p>
  
  <p>Questions:</p>
  
  <ul>
  <li>So what could be causing this security exception? </li>
  <li>How can we tell if we are indeed runing under full trust? </li>
  <li>What computer settings or configuration options do we need to change to avoid this security exception?</li>
  </ul>
  
  <p>Any help is appreciated</p>
  
  <h2>Here is the stack trace:</h2>
  
  <pre><code>Connect.Host.Connect.InitializeServiceHost(:0) Connect.Host.Connect.InitializeServiceHost(:0) [(null)] - Error: An error occurred creating the configuration section handler for system.serviceModel/bindings: That assembly does not allow partially trusted callers. (C:\Connect\MyApp\Host\Connect.Host.exe.Config line 54), stacktrace:    at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
     at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object&amp; result, Object&amp; resultRuntimeObject)
     at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object&amp; result, Object&amp; resultRuntimeObject)
     at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object&amp; result, Object&amp; resultRuntimeObject)
     at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object&amp; result, Object&amp; resultRuntimeObject)
     at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
     at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
     at System.Configuration.ConfigurationManager.GetSection(String sectionName)
     at System.ServiceModel.Activation.AspNetEnvironment.UnsafeGetSectionFromConfigurationManager(String sectionPath)
     at System.ServiceModel.Activation.AspNetEnvironment.UnsafeGetConfigurationSection(String sectionPath)
     at System.ServiceModel.Configuration.ConfigurationHelpers.UnsafeGetAssociatedSection(ContextInformation evalContext, String sectionPath)
     at System.ServiceModel.Description.ConfigLoader.LookupChannel(ContextInformation configurationContext, String configurationName, ContractDescription contract, EndpointAddress address, Boolean wildcard, Boolean useChannelElementKind, ServiceEndpoint&amp; serviceEndpoint)
     at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
     at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
     at System.ServiceModel.EndpointTrait`1.CreateSimplexFactory()
     at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)
     at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()
     at System.ServiceModel.ClientBase`1..ctor()
     at Connect.BL.EndpointManager.RegisterEndpoint(Int32 endpointId)
     at Connect.Host.Connect.InitializeServiceHost() for endpoint 0
  </code></pre>