title: Changing .NET 4 Runtime Activation Policy For Dll Within C++ Code
body: <p>We've developed a C# 4.0 module that needs to be accessed from an unmanaged C++ program (as well as a Fortran program). The DLL gets loaded correctly and the method is available to the C++ program, but an exception gets thrown when calling the method that points to the C# code. For a visualization:</p>
  
  <pre><code>[Unmanaged C++ / Fortran Projects]  
    -&gt; controller.dll (unmanaged C++ within the C++ project)    
       -&gt; managed_wrapper.dll (managed C++ within the C# project)
          -&gt; C# 4.0 Project
  </code></pre>
  
  <p>The exception gets thrown when the controller attempts to call the managed C++ (using .NET 4.0 framework).</p>
  
  <p>My suspicions are that the following configuration needs to be applied, as we encountered an error previously when <a href="https://stackoverflow.com/questions/7124294/debugging-managed-net-code-called-from-unmanaged-c">creating a proof of concept</a>:</p>
  
  <pre><code>&lt;configuration&gt;
    &lt;startup useLegacyV2RuntimeActivationPolicy="true"&gt;
      &lt;supportedRuntime version="v4.0"/&gt;
    &lt;/startup&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>I applied it correctly for the aforementioned proof of concept, but that was on a stand-alone console application. Since the unmanaged C++ program is huge and the settings are not universal for every module, I'm unable to create a <code>MyApplication.exe.config</code> file with the above configuration and call it day.</p>
  
  <p>My question is this: Is it possible to apply that configuration to a specific DLL?</p>