nigel-sampson / octokit.caching

Caching Http Backend for Octokit
Apache License 2.0
8 stars 4 forks source link

Making things work with .NET Core 2.0 #1

Open patridge opened 6 years ago

patridge commented 6 years ago

I don't know if there are plans to migrate to supporting .NET Core (or .NET Standard), but I found that when I tried to use this library in a .NET Core 2.0 console app in Visual Studio for Mac, I ran into a few issues.

  1. In the usage example, I had to adapt this line…
new CachingHttpClient(new HttpClientAdapter(), new NaiveInMemoryCache()),

…to this, to get it to compile…

new CachingHttpClient(new HttpClientAdapter(() => HttpMessageHandlerFactory.CreateDefault(new WebProxy())), new NaiveInMemoryCache()),
  1. [The bigger issue.] When I actually ran the program, even without any use of the Connection instance just created, it will crash the console app without any exception details or mention of what the exception was in the program output (at least in Visual Studio for Mac).

Potential problem

I don't know the exact issue without any exception details, but I suspect it's some sort of assembly mismatch somewhere, since it did warn about the package being "restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'. "

Unfortunately, running the solution with the source cloned and a direct project reference to try to debug, it still failed silently.

Potential solution

To get things debug-friendly, I spun up a new .NET Standard 2.0 project, added a reference to Microsoft.Net.Http and Octokit, and updated the IHttpClient implementation to include the new Dispose and SetRequestTimeout methods.

Once I had that, everything built fine, and my destination project started working without any issues.

The source for the .NET Standard project is in a branch on my fork. I can also port the various required code updates to the .NET Framework projects, but maybe the .NET Standard option would work going forward for multiple consuming frameworks.

If a pull request would be helpful, let me know. From there, I can try to make any other changes needed to go make it merge-worthy. For example, the Octokit.Caching.Tests and Octokit.Caching-NetCore45 projects do not load on Visual Studio for Mac, so I haven't even run those tests yet.

nigel-sampson commented 6 years ago

A pull request would be awesome thanks. Sorry took me a while to get back to you on this.

mcgear commented 5 years ago

Did this ever get merged?

nigel-sampson commented 5 years ago

There was never a PR, not sure there's any value these days. I haven't put in the effort to keep this up to date with Octokit.

patridge commented 5 years ago

Sorry, I totally missed the PR request way back in that first reply. I was trying to use this library for a project back in 2018 that was later abandoned. So, not only did I not solve the problem, but I'm pretty far from this world too. I'm guessing someone interested in getting this all working would need to rebuild things baked into a new .NET Core solution.