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.
Part of my plugin tries to get a worksheet by name:
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;
When I run as a standalone application (outside of our main application) the above code works fine.
However when I run the above code as a plugin from our main application I get the following execption:
dynamic operations can only be performed in homogenous appdomain
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.
<NetFx40_LegacySecurityPolicy enabled="true"/>
Regardless of this condition our client still wants this feature added. There must be some way of getting the Excel functionality to work.