This C# applications use EPPlus.
As it is, it works fine. I can export a DataGridView
to an Excel file like so:
ExcelPackage package = new ExcelPackage();
using ((package)) // use EPPlus
{
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(pageTitle);
DataTable dataTable = GetDataTableFromDataGridView(dataGridView);
worksheet.Cells["A1"].LoadFromDataTable(dataTable, true);
worksheet.View.FreezePanes(2, 1); // freeze first row
worksheet.Row(1).Style.Font.Bold = true;
worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();
FileUtilities.IsFileOpen(ExcelFile);
package.SaveAs(ExcelFile); // exception if file is open in excel
string message = null;
message = "Open file?";
string title = null;
title = pathAndFile + " created";
DialogResult result = MessageBox.Show(message, title, MessageBoxButtons.YesNo);
if (result == DialogResult.No)
{
// just close message box
}
else if (result == DialogResult.Yes)
{
System.Diagnostics.Process.Start(pathAndFile); // open excel file
}
}
However, if I make any change to this code, it causes an exception to be thrown. Even if I just add this line:
int x = 0;
it causes the exception:
System.IO.FileLoadException
HResult=0x80131040
Message=Could not load file or assembly 'EPPlus, Version=4.0.5.0, Culture=neutral, PublicKeyToken=ea159fdaa78159a1' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
If I look in the Project References, I see an EPPlus entry:
Aliasas : global
Copy Local : True
File Type : Assembly
Runtime Version : v4.0.30319
If I remove the new line, the exception does not occur and the code executes normally, i.e. it exports to the Excel file.
What is going wrong?
User contributions licensed under CC BY-SA 3.0