1

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.

5
  • dynamic probably refers to the type of wb. more context would be helpful. Jun 23, 2014 at 20:06
  • The type of wb is an Excel WorkBook. I'm not sure what other information to provide.
    – James
    Jun 23, 2014 at 20:10
  • Not to be snarky, but "Excel Workbook" is not a valid type name. More code around this call could be helpful. How did you get a hold of wb? There are many, many ms and non ms libraries that allow for interacting with excel, so your question is really ambiguous. Jun 23, 2014 at 20:16
  • I am using the Microsoft Excel library (Microsoft.Office.Interop.Excel). I have updated the above code to give more detail.
    – James
    Jun 23, 2014 at 20:24
  • I resolved the issue and changed the sample code above. For some reason I had to cast the object coming out of the Sheets collection to a Workbook which for some reason wasn't required in the stand alone application. Also, I had a typo on the type name. It should have been a "." instead of a space like "Excel.Workbook". The type name is "Workbook" in the "Excel" namespace.
    – James
    Jun 30, 2014 at 19:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.