title: C# CSharpCodeProvider: executing method in "compiling assembly" without adding reference
body: <p>I am using <code>CSharpCodeProvider</code> to compile C# into a dynamic assembly which contains methods that are called by an external software.</p>
  
  <p>Let's take the following code string that I am compiling dynamically:</p>
  
  <pre><code>public static class Foo 
  {
      public static object Bar(a, b) {
           return NameSpace.Type.Method(a, b); // Need to call original/compiling assembly
      }
  }
  </code></pre>
  
  <p>What I really want to do when calling <code>NameSpace.Type.Method</code>, is to call a method inside the assembly that originally compiled the C# code (i.e. the one using the <code>CSharpCodeProvider</code>).</p>
  
  <p>That said, I cannot use <code>ReferencedAssemblies.Add</code> to pass it into the <code>CSharpCodeProvider</code>. This is because my assembly (DLL) is wrapped in such a way that it is dynamically loaded - i.e. it exists nowhere on the file system.</p>
  
  <blockquote>
    <p>Is there any other way to call a method on the compiling assembly?</p>
  </blockquote>
  
  <h3>Post-Closure Edit:</h3>
  
  <p>The <a href="https://stackoverflow.com/questions/2830160/c-sharp-referencing-a-type-in-a-dynamically-generated-assembly">referenced question</a> uses <code>ReferencedAssemblies.Add</code> which, as I stated above, I am unable to use due to the fact that the calling assembly does not actually exist on the file system and only in memory.</p>
  
  <p>Furthermore, the referenced question refers to the scenario of calling one dynamically compiled assembly from another.  My scenario is different in that I need to call the original (compiling) assembly - and it does not exist as a DLL on the system since it is loaded from within a packed module by a third-party application.</p>