Reputation: 201
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.
Upvotes: 3
Views: 6535
Reputation: 998
I had a similar problem while using impersonation
and what worked for me is to add assembly like that :
using (WindowsLogin wi = new WindowsLogin(_options.UserName, _options.Domain, _options.Password))
{
Assembly.Load("CsvHelper, Version=27.0.0.0, Culture=neutral, PublicKeyToken=8c4959082be5c823");
WindowsIdentity.RunImpersonated(wi.Identity.AccessToken, () =>
{
your code goes here ...
});
}
Upvotes: 0
Reputation: 1764
We fixed this by copying over the *.deps.json file which we normally don't do. Also the CsvHelper.dll file's modified timestamp is in the past.
Upvotes: 0
Reputation: 201
I'm going to answer my own question rather than delete it, in the hope that it helps someone else.
I "fixed" this by:
Upvotes: 5