无法加载文件或程序集 'CsvHelper'(C#、VS2019、CSVHelper)

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

我有一个 class 库,它使用 CSVHelper (v19.0.0)。我在 VS2019(版本 16.5.5;.NET 4.8.03752)中通过 Nuget 安装了 CSVHelper,并且可以确认包在 'should' 所在的位置(基于检查我的 project/dependencies/package/CSVHelper/properties,显示 C:\Users\[my_name]\.nuget\packages\csvhelper.0.0)。 [编辑:我检查了我的 [解决方案名称].csproj 文件,发现其中包含 PackageReference Include="CsvHelper" Version="19.0.0"]

但是,当我尝试调用我的 class 库中的方法之一时,我收到如下所示的错误消息。

我用谷歌搜索了这个问题,其他人也遇到了与早期版本的 CSVHelper(例如 https://github.com/JoshClose/CsvHelper/issues/944)相同的问题,但他们的解决方案对我不起作用。我试过:1)清理和重建解决方案; 2) 删除 CSVHelper 然后通过 Nuget 重新安装;和 3) 从我的 C 驱动器上的 .nuget 文件夹中删除所有旧版本的 CSVHelper。问题继续出现。将不胜感激。

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.
  

我将回答我自己的问题而不是删除它,希望它能帮助其他人。

我通过以下方式“解决”了这个问题:

  1. 手动将 CsvHelper.dll 复制到我的 bin\Debug\netstandard2.0 文件夹 项目
  2. 直接添加对该 dll 的引用
  3. 删除对 CsvHelper 的 Nuget 引用