23

I have a web in ASP.Net Core (4.6.1 framework) that uses Facebook and MS external login that I created with Visual Studio 2015 and opened in the new Visual Studio 2017 that came out yesterday. VS2017 made a few changes related to the csproj, project.json, etc files.

The site compiled and executed fine except for one part. If I did a Facebook or Microsoft external login, the site displayed this trap:

FileLoadException: Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

System.Net.Http.WinHttpHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
AggregateException: Unhandled remote failure.

Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler+<HandleRemoteCallbackAsync>d__6.MoveNext()

The url in the browser showed that it was attempting to return from the external login to the local (https://localhost:44321/signin-facebook?code=... or /signin-microsoft).

The version number of the System.Diagnostics.DiagnosticSource.dll (and System.Net.Http.dll) is 4.6.24705.1.

I started a new VS2017 project from scratch with Facebook and MS login added and it worked fine - getting me logged on without the trap. The dll's were the same versions.

Comparing the two csproj files showed differences but nothing obvious (nothing related to System dlls):

Differences in csproj file

GarDavis
  • 1,309
  • 3
  • 14
  • 23

5 Answers5

41

What solved it for me was to add a NuGet reference to System.Net.Http (version 4.3.1) to the newly migrated project. https://www.nuget.org/packages/System.Net.Http/

Haukman
  • 3,726
  • 2
  • 21
  • 33
  • 2
    Thank you, i hit the same error today upgrading my project to VS2017 – Gillardo Mar 11 '17 at 21:10
  • 2
    This error hit us too. Here’s a related bug on GitHub for reference: https://github.com/aspnet/JavaScriptServices/issues/487 – poke Mar 15 '17 at 15:21
  • Looks like their solution was to add System.Net.Http as well. – Haukman Mar 15 '17 at 17:54
  • @Haukman After bringing my XUnit projects over from VS2015 to VS2017 I let it do its thing and replace the project.json files with .csproj and kept getting this System.Diagnostics error. My test project references a dll that makes API calls that uses System.Net.Http. Why in the world would the test project need to reference this to work? Somehow if I run the tests using the ReSharper Xunit test tool this reference is not needed. – Blake Rivell Jun 13 '17 at 21:05
  • I can't tell for sure, but it may be that one of the dependencies are using it and doesn't have it listed as a NuGet dependency. I think the System.Net.Http is a little "special" since it's also included natives in the .NET Framework, it always seems to be the dependency that messes up my project, adding it "solves" a lot of issues. – Haukman Jun 14 '17 at 07:14
  • I was using OpenTelemetry with Http library but it must not have included the required dependency in install when I installed the package. Thanks! – Kyle Burkett Jul 17 '23 at 19:49
11

The recommended answer did not resolve my issue. I was getting this error when trying to reference a .Net 4.6.2 lib in a .Net Core 2 project.

To resolve the issue I had to add the Microsoft.Windows.Compatibility nuget package. Credit to: https://medium.com/@ans_ashkan/asp-net-core-and-windows-event-log-75770a80a666

Bynho
  • 572
  • 6
  • 16
9

In References 'System.Diagnostics.DiagnosticSource' not included in solution

On installing latest version "5.0.1" of 'System.Diagnostics.DiagnosticSource' in NUget solved my issue. Hope it will fix yours also.

Fayazz B N
  • 117
  • 1
  • 2
4

I had the same issue and weirdly enough, problem resolved with updating Microsoft.ApplicationInsights versions. 2.20.0 is the version to go (for me). I don't know the connection between these packages but that's what happened.

boyukbas
  • 1,137
  • 16
  • 24
3

People using .NET Core web applications monitored with Application Insights hosted in App Services facing this issue

This when .NET Core web application has a dependency on 'System.Diagnostics.DiagnosticSource%u2019 binary and has this binary file deployed to /wwwroot/ folder, which is rare.

Work Around: Please set previous version of monitoring extension by changing this app setting if you experience the above issue: ApplicationInsightsAgent_EXTENSIONVERSION=2.8.24

After doing this please restart the application.

Here is the source

Dakshal Raijada
  • 1,261
  • 8
  • 18