title: Getting CefSharp to play nice with CSScript
body: <p>I have an application that uses a <code>CefSharp.OffScreen</code> browser to do a bit of scraping work.  It runs in a scripting environment using CSScript to execute a dynamically-loaded class that calls CefSharp to do the work.</p>
  
  <p>CefSharp works perfectly fine in a <code>bin</code> environment.  <a href="https://github.com/cefsharp/CefSharp/issues/601" rel="nofollow noreferrer">There's even a way to place all of the CefSharp files in their own folder, using <code>ProbingPath</code></a>.  But this only works if CefSharp is running in the same folder as your primary executable, or in the <code>ProbingPath</code> folder you have set up.  <em>ProbingPath can only be set up as a subfolder of the executable path.</em></p>
  
  <p>CefSharp is marshalled from <a href="https://stackoverflow.com/q/36923015/102937">a simple DLL I wrote</a> called <code>MyCompany.Browser</code>.  It has a single method in it called <code>Browse</code> that accepts an url string and returns an html string.  It does this by spinning up a <code>CefSharp.OffScreen</code> browser and executing it, and this all works perfectly fine in an ordinary bin environment.</p>
  
  <p>In my dynamically-loaded script that CSScript executes, I have code that is functionally equivalent to this (a greatly-simplified, highly-contrived test):</p>
  
  <pre><code>using MyCompany.Browser;
  
  public string GetResult(string url)
  {
      using (var browser = new CefSharpHeadlessBrowser())
      {
          return browser.Browse(url);
      }
  }
  </code></pre>
  
  <p>The way CSScript works is, if you give it a <code>using MyCompany.Browser;</code> reference, it will look in the folder from which it was executed, find the dll named MyCompany.Browser.dll, and load it for you.   <code>CefSharpHeadlessBrowser</code> is a type in this <code>MyCompany.Browser</code> namespace, in a DLL called <code>MyCompany.Browser.dll</code>, in the primary bin folder on a server somewhere, which CSScript happily instantiates.  </p>
  
  <p>However, when I try to execute the <code>browser.Browse()</code> method, this happens:</p>
  
  <pre><code>Unable to locate required Cef/CefSharp dependencies:
  Missing:CefSharp.BrowserSubprocess.exe
  Missing:CefSharp.BrowserSubprocess.Core.dll
  Missing:CefSharp.Core.dll
  Missing:CefSharp.dll
  Missing:icudtl.dat
  Missing:libcef.dll
  </code></pre>
  
  <p>These messages are coming from <a href="https://github.com/cefsharp/CefSharp/blob/master/CefSharp/DependencyChecker.cs" rel="nofollow noreferrer">a <code>CheckDependencies()</code> method in <code>CefSharp.dll</code></a>, which MyCompany.Browser.dll has loaded.  However, that's as far as the loading process gets.  MyCompany.Browser has loaded because it's in the same folder as CSScript; CefSharp.dll loaded long enough to run its dependency checker and give me the above error messages because MyCompany.Browser.dll has a direct reference to it.  </p>
  
  <p>But the rest of CefSharp didn't load, because the dynamically-loaded script is not running in the same bin folder.  Instead, it's running in:</p>
  
  <pre><code>c:\Users\admin\AppData\Local\Temp\CSSCRIPT\dynamic\879ec55a-f761-4306-a79c-1af6cf08b312.tmp
  </code></pre>
  
  <p>I would love for someone to be able to tell me that CefSharp has a registry entry, an <code>app.config</code> element, or something that will notify CefSharp that "Here is where you can find all of your files."  Is there something like that, and if not, is there some other way to fix this?</p>