Reputation: 19183
I am using asp.net 4.5 framework. I just downloaded EPPLus using NUget Package. I then used the code given at the following link.
http://epplus.codeplex.com/wikipage?title=WebapplicationExample
And add following code on click event of a button. After clicking the button, i am getting following error.
Could not load file or assembly 'EPPlus, Version=3.1.3.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)
Please suggest If I am making any stupid mistake.
DataTable table = new DataTable();
table.Columns.Add("Dosage", typeof(int));
table.Columns.Add("Drug", typeof(string));
table.Columns.Add("Patient", typeof(string));
table.Columns.Add("Date", typeof(DateTime));
table.Rows.Add(25, "Indocin", "David", DateTime.Now);
table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
using (ExcelPackage pck = new ExcelPackage())
{
//Create the worksheet
ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Demo");
//Load the datatable into the sheet, starting from cell A1. Print the column names on row 1
ws.Cells["A1"].LoadFromDataTable(table, true);
//Format the header for column 1-3
using (ExcelRange rng = ws.Cells["A1:C1"])
{
rng.Style.Font.Bold = true;
rng.Style.Fill.PatternType = ExcelFillStyle.Solid; //Set Pattern for the background to Solid
rng.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(79, 129, 189)); //Set color to dark blue
rng.Style.Font.Color.SetColor(Color.White);
}
//Write it back to the client
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment; filename=ExcelDemo.xlsx");
Response.BinaryWrite(pck.GetAsByteArray());
}
Upvotes: 3
Views: 13705
Reputation: 11245
I met a case where my solution was prepared for test purposes and consisted of several projects which had reference to EPPlus. The problem was I referenced ver 4 to only one project and I left others with older version of EPPlus (esp. the executable one had older ver). The result was that after build process the folder contained older EPPlus and during the run-time I used linked project with newer EPPlus (so the project was not able to find proper version of EPPlus). After I referenced the same version of EPPlus to all projects, the exception was not thrown anymore.
Upvotes: 5
Reputation: 88062
This part
The located assembly's manifest definition does not match the assembly reference.
Suggests that the version number of the assembly isn't matching the version number in your config file. See this question:The located assembly's manifest definition does not match the assembly reference
Upvotes: 0