The setup is as follows:
- a .NET Standard 2.0 library
- a NUnit test project for it, targeting .NETFramework 4.6.1
Latest VS 2017, latest NUnit.
I've been working on the project on weekend from home, uploaded my work to git and today started working from work (I've already worked from both places before). Only now I found that something was wrong with the project (I don't remember very well what was wrong at the start, but it seems the problem was the same as I have now, described later).
After fiddling around to unrepairable state with it, I wholly deleted it and cloned the git repo anew.
The project compiles fine, but at runtime tests throw "Method not found" exception. A bit of poking around showed that the problem only manifests on one overload of the following method:
public static YNABClient GetInstance(HttpMessageHandler _handler)
{
if (instance is null)
{
instance = new YNABClient(_handler);
}
return instance;
}
public static YNABClient GetInstance() => GetInstance(new HttpClientHandler());
The one without parameters is fine, the one with is not. Deleting and adding library as a reference to tests, deleting and adding both test and library project. Other solutions for similar situations I found on the internet all pertain to ASP.NET MVC, which is not my case, though this question did lead me to checking overloads and finding that one of them actually works.
At home everything still works fine, though I have yet to try to delete and reinstall the project as I did at work. This leads to 2 possible sources for problems: environment, though I haven't managed to find a meaningful difference, or git, though I use a "stock" git ignore for VS (this one), so there shouldn't be problems there. The basic setup for my projects didn't change during weekend and worked before, so something broke from recent fiddling.
Also, if I add a console application(.Net Framework 4.6.1) to solution and try calling the problematic method from it, it actually works fine.
If that would help, my github for the project is here
I've been asked for calling examples in the comments. Basically, I have 2 Test Fixture classes with different setups - one for real API calling for ease of debugging actual use, and one with faking it, as per good test practices. Works:
[OneTimeSetUp]
public void Setup()
{
ynabClient = YNABClient.GetInstance();
ynabClient.RefreshAccessToken(ApiKeys.AccessToken);
}
Throws exception:
[OneTimeSetUp]
public void Setup()
{
handler = new StubHandler();
ynabClient = YNABClient.GetInstance(handler);
}
Some poking around shows that my problem is quite likely related to System.Net.Http versioning discrepancy with .NET Framework and .NET Standard, that is quite a widespread problem if you google it. However none of the examples I dug up exhibit my particular symptoms, and I'm not yet sure what to do. And why everything works fine on my home PC.