Search code examples
c#nugetexceldatareader

"ExcelReaderFactory.cs not found" Error


I've downloaded ExcelDataReader from the Visual Studio Package Manager Console and followed the C# instructions on its Code Plex page http://exceldatareader.codeplex.com/, but, during run-time, I get an "ExcelReaderFactory.cs not found" message when the code fails at the ExcelReaderFactory. The entirety of my code block is below.

I've tried removing and reinstalling the Nuget package and searching for hours, coming upon an answer from this site: ExcelReaderFactory.cs not found. I tried catching a possible exception, but none was caught in my code. Is the exception only in the ExcelDataReader source code, to which I do not have access, and not in my code? What is the solution to this error? Thanks very much in advance.

[HttpPost]
public ActionResult UploadForecasts(HttpPostedFileBase ForecastsFile)
{
     try
     {
          string myPath = "C:\\Uploads\\" + ForecastsFile.FileName;
          ForecastsFile.SaveAs(myPath);
          System.IO.FileStream stream = System.IO.File.Open(myPath, FileMode.Open, FileAccess.Read);

          IExcelDataReader ForecastsReader = myPath.Contains(".xlsx")
               ? Excel.ExcelReaderFactory.CreateOpenXmlReader(stream)
               : Excel.ExcelReaderFactory.CreateBinaryReader(stream);
     }
     catch (Exception ex)
     {
          Console.WriteLine(ex.Message);
     }
}

Solution

  • This happens to me as well. There isn't an exception being thrown necessarily, and honestly, as long as you don't try to step into the ExcelDataReader functions, it won't hurt anything.

    In other words, set a breakpoint after the ExcelDataReader code, and just click Continue and it'll continue just fine. Hope this helps. It is trying to step into the DLL, but it can't. Just continue over it and it'll move on without throwing that error.