Search code examples
c#.netnuget.net-standard-2.0github-package-registry

Private nuget reference break .NET Core 2 webapp at runtime


Here's the situation.

I have 2 simple dll compiled in .NET standard 2.0 (for compatibility reasons). The first one (let's call it A) has no external references except for NETStandard.Library (2.0.3). The second one (let's call it B) references Microsoft.Extensions.Loggin.Abstractions (5.0.0), Newtonsoft.Json (13.0.1) and of course NETStandard.Library (2.0.3). Both compile & run (local unit tests) without errors.

Since I need them to be shared through several projects I'm using a private GitHub package repository; I'm able to get them from the NuGet Package Manager in Visual Studio. The NuGets creation & deploy is done thanks to a GitHub action.

Both dlls are currently used without any issue in a .NET Core 3.1 REST project.

The problems started when I tried to use them in a .NET Core 2.2 REST project: while everything was fine locally (debug), after the publish and the deploy I figured out that the dll B was breaking the whole app somehow.

The app starts but every request to the REST services never receives any response (I think that it never reaches the endpoint, to tell the truth). No logs/errors from the app or IIS in text files and Event Viewer.

I figured out that's not related to the code beacuse referencing the dll B without using anyone of its methods is enought to break the whole thing.

No problems at all with the A dll.

Here's what I've tried (not exactly in this order):

  • Removed every reference and commented every line of code from B -> still breaking the app (and this made me realize that was not a code or reference problem)
  • Referenced it from another project: WebApp .NET Core 2.0 this time -> still breaking the app
  • Referenced it from a brand new empty project in .NET Core 2.2 (the Weather REST service that Visual Studio uses as starting template) -> no problems at all
  • Added to the Weather REST service every dependecy that other apps have (to spot any incompatibility) -> still working on the Weather project
  • Created & pushed the NuGet package manually -> still breaking the app
  • Deployed on two different machines (one internal and one AWS) -> still breaking the app on both
  • Referenced it as a local assembly (and not from NuGet) -> it works!

So, even the NuGet reference to the empty dll breaks the app(s), while as local assembly doesn't. It's not a framework/environment problem since the new .NET Core 2.2 project and the other .NET Core 3.1 project work well (on the same machines). It's not a .NET Standard compilation problem because the A dll follows exactly the same deploy method and it works everywhere. No errors thrown. Everything is fine while debugging.

I'm desperate. Any advice?

Thanks


Solution

  • I finally figured it out, even if some things are still not clear.

    My project in .NETCore2.2 uses AspNetCore.All with a specific version (2.2, according to the framework) and includes some Microsoft.Extensions.Logging dlls.

    My B dll references Microsoft.Extensions.Logging.Abstractions 5.0: downloading B as NuGet makes the package manager resolve the references, so basically I was going on with a v5.0 in my app while the app was looking for a v2.2 in the framework (probably in the GAC, this could explain why a brand new app with the same references was working well).

    So I solved by using

    AppDomain.CurrentDomain.FirstChanceException += (sender, eventArgs) => 
    {
      //Log everything here
    }
    

    and I discovered that it was throwing an error about a class that i was not using at all; the class was present in Logging.Abstractions 5.0 but not in 2.2.

    Since I don't need any feature of the 5.0, I downgraded it to 2.0 and now it works like a charm.

    Still don't know why no exception was logged in the event viewer.