Could not load file or assembly 'CsvHelper' (C#, VS2019, CSVHelper)

0

I have a class library which uses CSVHelper (v19.0.0). I installed CSVHelper via Nuget in VS2019 (Version 16.5.5; .NET 4.8.03752), and can confirm that the package is where it 'should' be (based on checking my project/dependencies/package/CSVHelper/properties, which shows C:\Users\[my_name]\.nuget\packages\csvhelper\19.0.0). [EDIT: I have checked my [solution name].csproj file and see that contains PackageReference Include="CsvHelper" Version="19.0.0"]

However, when I try to call one of the methods in my class library, I get the error message shown below.

I have Googled this and others encountered the same problem with earlier versions of CSVHelper (e.g. https://github.com/JoshClose/CsvHelper/issues/944) but their solutions have not worked for me. I have tried: 1) cleaning and rebuilding the solution; 2) removing CSVHelper then reinstalling via Nuget; and 3) removing all old versions of CSVHelper from the .nuget folder on my C drive. The problem continues to appear. Help would be much appreciated.

System.IO.FileNotFoundException
  HResult=0x80070002
  Message=Could not load file or assembly 'CsvHelper, Version=19.0.0.0, Culture=neutral, PublicKeyToken=8c4959082be5c823' or one of its dependencies. The system cannot find the file specified.
  
c#
visual-studio
csvhelper
asked on Stack Overflow Jan 8, 2021 by user42108 • edited Jan 8, 2021 by user42108

1 Answer

1

I'm going to answer my own question rather than delete it, in the hope that it helps someone else.

I "fixed" this by:

  1. manually copying the CsvHelper.dll to the bin\Debug\netstandard2.0 folder for my project
  2. adding a reference directly to that dll
  3. removing the Nuget reference to CsvHelper
answered on Stack Overflow Jan 8, 2021 by user42108

User contributions licensed under CC BY-SA 3.0