Click here to Skip to main content
15,797,721 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a c# console app. Writing data from DB to Excel using Epplus.

It works Locally. However, On my Test server it doesn't work. Error Message below

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or ass
embly 'EPPlus, Version=, Culture=neutral, PublicKeyToken=ea159fdaa78159a1
' or one of its dependencies. The system cannot find the file specified.
   at UserAndVehicleList.DAL.GetUserList()
   at UserAndVehicleList.Program.Main(String[] args)

What I have tried:

foreach (DataTable table in ds1.Tables)
                          using (ExcelPackage excel = new ExcelPackage())

                              // Determine the header range (e.g. A1:D1)
                             // string headerRange = "A1:" + Char.ConvertFromUtf32(headerRow[0].Length + 64) + "1";

                              // Target a worksheet
                              var worksheet = excel.Workbook.Worksheets["Worksheet1"];

                              // Popular header row data

                              worksheet.Cells["A1"].Style.Font.Bold = true;
                              //worksheet.Cells[headerRange].Style.Font.Size = 14;

                              //ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Accounts");
                              worksheet.Cells["A1"].LoadFromDataTable(table, true);

                              root = @"C:\ " + EntityName + "";

                              // If directory does not exist, create it.
                              if (!Directory.Exists(root))

                              path = root + @"\" + fileName;

                              //FileInfo excelFile = new FileInfo(@"C:\Users\amir\Desktop\test.xlsx");
                              FileInfo excelFile = new FileInfo(path);
Updated 11-Oct-19 0:46am

1 solution

So make sure that the EPPlus assembly is included as part of your setup and deployment project and it will be installed correctly when you install the app on the server.

Unless you just copied the EXE file without any of the DLL files it needs to work, of course ...
Share this answer
Member 14370529 11-Oct-19 6:14am    
i copied the EXE file without any of the DLL file
OriginalGriff 11-Oct-19 6:34am    
That's like emailing someone but not attaching any of the files that the email refers to ... If the EXE file uses external DLL's they have to be part of the .NET framework, or included in the setup package.
Member 14370529 11-Oct-19 7:58am    
WOrked Thanks @OriginalGriff
OriginalGriff 11-Oct-19 8:01am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900