title: Excel dynamic operations can only be performed in homogenous appdomain error
body: <p>The company I work for has the option to create plugins for our main product. I am currently working on a plugin. The plugin needs to read in from an Excel file. </p>
  
  <p>Part of my plugin tries to get a worksheet by name:</p>
  
  <pre><code>Excel.Application excelApp = new Excel.Application();
  Excel.Workbook wb = excelApp.Workbooks.Open(fileName, Type.Missing, Type.Missing,
                                           Type.Missing, Type.Missing,
                                           Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                           Type.Missing, Type.Missing, Type.Missing, Type.Missing);
  Excel.Worksheet ws = wb.Sheets[SheetName] as Excel.Worksheet;
  </code></pre>
  
  <p>When I run as a standalone application (outside of our main application) the above code works fine.</p>
  
  <p>However when I run the above code as a plugin from our main application I get the following execption:</p>
  
  <pre><code>dynamic operations can only be performed in homogenous appdomain
  </code></pre>
  
  <p>I have done some research and found that the legacy security policy is related. For other reasons that I am unaware of and cannot change our main product must run with legacy security policy turned on.</p>
  
  <pre><code>&lt;NetFx40_LegacySecurityPolicy enabled="true"/&gt;
  </code></pre>
  
  <p>Regardless of this condition our client still wants this feature added. There must be some way of getting the Excel functionality to work.</p>