Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

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

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].nugetpackagescsvhelper19.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.
  

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 binDebug etstandard2.0 folder for my project
  2. adding a reference directly to that dll
  3. removing the Nuget reference to CsvHelper

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...