title: Unable to load assembly exception in a library application consumed by a Windows service
body: <p>I re-post here a question that I have already ask on the Dynamics community, but I guess I will not get any answer from their :</p>
  
  <p><a href="https://community.dynamics.com/ax/f/33/t/171159" rel="nofollow">https://community.dynamics.com/ax/f/33/t/171159</a></p>
  
  <p>and I don't think knowledging in Dynamics is necessarily required to understand my problem.</p>
  
  <p>I have a c# application in three parts :
  - Windows service
  - WPF view
  - Shared library</p>
  
  <p>(in the Dynamics forum post, it's a console application instead of a windows service, but the deal is the same)</p>
  
  <p>The service application calls the method "Test()" of this class, which is in the library project :</p>
  
  <pre><code>public class Program
  {
      private const string _connectionString = "[...]";
      private const long _channelId = 5637146827;
  
      public static void test()
      {
          var dllConfigPath = string.Concat(AppDomain.CurrentDomain.BaseDirectory, "my_dll.config");
  
          var configFileMap = new ExeConfigurationFileMap()
          {
              ExeConfigFilename = dllConfigPath
          };
  
          var appConfigFile = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
  
          // configuration is successfully loaded at this point
          var configSection = (CommerceRuntimeSection)appConfigFile.GetSection("commerceRuntime");
  
          // an exception is throw here
          var commerceRuntimeConfiguration = new CommerceRuntimeConfiguration(configSection, _connectionString, true);
  
          var commercePrincipal = new CommercePrincipal(new CommerceIdentity(_channelId, Enumerable.Empty&lt;string&gt;()));
  
          var runtime = CommerceRuntime.Create(commerceRuntimeConfiguration, commercePrincipal);
  
          ChannelManager channelManager = ChannelManager.Create(runtime);
      }
  }
  </code></pre>
  
  <p></p>
  
  <p><strong>An exception "unable to load file or assembly Microsoft.Dynamics.Commerce.Runtime.Services" is thrown at the line
  "new CommerceRuntimeConfiguration()"</strong></p>
  
  <p>I don't have source code of this class, I just know it takes a section of config file in argument.
  The config file is describe below, it's in the library project, not in the service project (it might be an important point).</p>
  
  <p><a href="http://img11.hostingpics.net/pics/834895config.png" rel="nofollow">http://img11.hostingpics.net/pics/834895config.png</a> (sry for this link, I fail to post the XML directly)</p>
  
  <p>As I explain on the Dynamics forum, all the DLL required are properly includes in the library project.</p>
  
  <p>I repost the same conclusion :</p>
  
  <p>The only solution I have found, which is not acceptable from my point of view, is to :</p>
  
  <ul>
  <li><p>copy the .config file on the service windows application</p></li>
  <li><p>add all the dlls in the service windows application references. But I still need it in the library application (without, the code in the library doesn't compile) : so basically, I have to references twice all the DLLs...</p></li>
  </ul>
  
  <p><strong>How can I make this application architecture works (without copy config and DLLs in the service) ?</strong></p>
  
  <p>Thanks,</p>
  
  <p>Charles</p>