title: c# Class Library Project - Load DLL from same folder?
body: <p>I'm working on a plugin for a existing C# .NET Program. It's structured in a manner where you put your custom .dll file in Program Root/Plugins/your plugin name/your plugin name.dll</p>
  
  <p>This is all working well, but now I'm trying to use NAudio in my project. </p>
  
  <p>I've downloaded NAudio via Nuget, and that part works fine, but the problem is that it looks for the NAudio.dll in Program Root, and not in the folder of my plugin.</p>
  
  <p>This makes it hard to distribute my plugin, because it would rely on users dropping the NAudio.dll in their Program Root in addition to putting the plugin into the "Plugins" folder.</p>
  
  <p>Source:
  <strong>SettingsView.xaml:</strong></p>
  
  <pre><code>&lt;Button HorizontalAlignment="Center"
      Margin="0 5"
      Width="120"
      Command="{Binding SoundTestCommand,
      Source={StaticResource SettingsViewModel}}"
      Content="Sound Test" /&gt;
  </code></pre>
  
  <p><strong>SettingsViewModel.cs:</strong></p>
  
  <pre><code>using NAudio.Wave;
  .
  .
  .
      public void SoundTest()
      {
          IWavePlayer waveOutDevice;
          WaveStream mainOutputStream;
          WaveChannel32 inputStream;
  
          waveOutDevice = new WaveOut();
  
          mainOutputStream = new Mp3FileReader(@"E:\1.mp3");
          inputStream = new WaveChannel32(mainOutputStream);
  
          inputStream.Volume = 0.2F;
  
          waveOutDevice.Init(mainOutputStream);
          waveOutDevice.Play();
      }
  </code></pre>
  
  <p>How can I get C# to look for NAudio in Program Root/Plugins/my plugin name/NAudio.dll instead of looking for it in Program Root/NAudio.dll ?</p>
  
  <p>I'm using VS Express 2013, Target Framework is 4.5 and Output type is Class Library.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I found 2 ways to make this work ( I'm not sure what the pros and cons of both methods are - if anyone knows I would appreciate additional information ).</p>
  
  <ol>
  <li><p>Using the NuGet Package <strong>Costura.Fody</strong>.</p>
  
  <p>After installing the NuGet package, I simply had to set all other References "Copy Local" to "<strong>False</strong>" and then set "Copy Local" for NAudio to "<strong>True</strong>".</p>
  
  <p>Now when I build, the NAudio.dll is compressed and added to my own DLL.</p></li>
  <li><p>Using the <strong>AssemblyResolver</strong> outlined below.</p>
  
  <p>It didn't work right away though, so here is some additional information that may help anyone facing the same issue:</p>
  
  <p>I put Corey's code as he posted it into the Helpers folder.</p>
  
  <p>My entry point is Plugin.cs, the class is <code>public class Plugin : IPlugin, INotifyPropertyChanged</code></p>
  
  <p>In there, the entry method is <code>public void Initialize(IPluginHost pluginHost)</code>, but simply putting <code>PluginResolver.Init(path)</code> did not work.</p>
  
  <p>The host program uses WPF and is threaded and I had to use a dispatcher helper function of the host program to get it to work: <code>DispatcherHelper.Invoke(() =&gt; Resolver.Init(path));</code></p></li>
  </ol>
  
  <p>As mentioned, I'm currently unsure which method to use, but I'm glad I got it to work. Thanks Corey!</p>