2
votes

SignalR Core pre-realease with ASP.net Core 2.0 in VS 2017 15.3 at runtime exception .. Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=4.0.2.1

im getting an exception at runtime and not build time Exception thrown: 'System.IO.FileLoadException' in Microsoft.AspNetCore.Hosting.dll An unhandled exception of type 'System.IO.FileLoadException' occurred in Microsoft.AspNetCore.Hosting.dll Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=4.0.2.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

the line of code that is erroring is...

    public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .Build();

here is excerpt of the log file for the build after run dotnet build -v d >build.log

     Dependency "System.Diagnostics.DiagnosticSource, Version=4.0.2.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51".
         Could not resolve this reference. Could not locate the assembly "System.Diagnostics.DiagnosticSource, Version=4.0.2.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

D:\org\projects> dotnet --version 2.0.0-preview2-006497

PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.0.0-preview2-24707" PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-preview2-final"

1

1 Answers

2
votes

I ran into the same error when attempting to run a WebApi application after upgrading to Visual Studio 15.3 and .NET core 2.0. I used 15.3 to create a new WebApi project.

I got the error by simply trying to run the project as created by Visual Studio.

It turns out that I still had a preview version of the 2.0 SDK installed. This caused my project to reference the preview version of the Microsoft.NETCore.App NuGet package.

By uninstalling the preview SDK and installing the full 2.0 SDK (released August 11, 2017), I was able to get my project to run (this exception no longer popped up).