Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASP.NET Core 1.1 + Serilog.Seq compatibility issue when targeting NET462 #56

Closed
nvivo opened this issue Apr 4, 2017 · 8 comments
Closed

Comments

@nvivo
Copy link

nvivo commented Apr 4, 2017

I have some apps running with the new csproj format, but targeting the full framework, and when referencing Serilog.Seq there seems to be some compatibility issue around System.Diagnostics.DiagnosticSource.

Here is a sample app to reproduce:

App.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net462</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
    <PackageReference Include="Serilog.Sinks.Seq" Version="3.2.0" />
  </ItemGroup>
</Project>

Program.cs:

using Serilog;
using System;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Serilog.Debugging.SelfLog.Enable(Console.Error);

            Log.Logger = new LoggerConfiguration()
                .WriteTo.Seq("http://dummy")
                .CreateLogger();

            Log.Information("test");

            Console.ReadLine();
        }
    }
}

Run with:

dotnet restore
dotnet run

This gives me:

System.IO.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.

It seems Serilog.Seq requires System.Net.Http 4.0 which depends on System.Diagnostics.DiagnosticSource version 4.0, while ASP.NET Core 1.1 depends on 4.3. The build selects version 4.3 while the runtime tries to load 4.0. I suppose .NET should be generating assembly binding redirects for this, but it's not.

This issue doesn't happen if "netcoreapp1.1" is the target.

Now, if I add System.Diagnostics.DiagnosticSource 4.3 as a dependency to the project, the issue persists. If downgrade to 4.0, then I get lots of downgrade warnings for .NET components.

@nvivo nvivo changed the title .NET Core 1.1 + Serilog.Seq compatibility issue when targeting NET462 ASP.NET Core 1.1 + Serilog.Seq compatibility issue when targeting NET462 Apr 4, 2017
@nblumhardt
Copy link
Member

Hi Natan, thank you for the issue report.

I'm only just piecing together this scenarion, but I think there are two ways around this (unavoidable on our side AFAIK). They are:

  • If you're adding packages by editing the CSPROJ directly, you need <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> under the top <PropertyGroup>
  • Otherwise, if you instead use Install-Package Serilog.Sinks.Seq from the package manager console, the redirects will be added for you

Would it be possible to try out either method, and let us know what you have success with? Thanks!

@nblumhardt
Copy link
Member

Hi @nvivo - I think this and #57 are related; I've just pushed what I hope is a fixed version as: https://www.nuget.org/packages/Serilog.Sinks.Seq/3.3.0-dev-00110

Can you please let me know if this does the trick for you?

Many thanks!

@nvivo
Copy link
Author

nvivo commented Apr 8, 2017

Hi @nblumhardt, I had tried the previous workarounds but it didn't work. The assembly bindings were being generated, but not for System.Diagnostics.DiagnosticSource.

The 3.3 version solves the issue.

Looks like the problem is referencing System.Net.Http from GAC. This hardcodes the reference in the DLL and forces that specific version to be loaded during runtime. With nuget references, the build system resolves all dependencies and to a single version and is able to create bindings correctly.

Just an idea, but maybe you don't need a new build for NET46, just reference System.Net.Http >= 4.0 from nuget for NET45 too.

@nblumhardt
Copy link
Member

Awesome, thanks for the feedback, Natan. I think we'll give this package a few days in "dev" and then push it to master, since it's an annoying issue to track down for users.

@serilog/reviewers-core this is likely to affect all sinks that use System.Net.Http (it's not our issue, but we have a workaround).

On .NET 4.5, since the issue isn't triggered I might leave the dependency structure as-is for now, since we've been through more than a few iterations and breakages to get where we are today. (If it ain't broke, ... :-) )

@waynebrantley
Copy link

@nblumhardt
I have the latest package of all serilog/sinks.
I have asp.net core targeting full framework 4.6.1
I had this same exact issue.
I added the latest version of System.Net.Http package (4.3.2 as of now) and this fixed the issue.

Potentially you should have that as a dependency for the .net full framework 4.6.1 version of your package?

@nblumhardt
Copy link
Member

Thanks for the bump, @waynebrantley! This should have already been the case, but the 3.3.0 version of this sink was yet to be published with the fix.

Build is kicked off now, package should be on NuGet shortly.

@alexeyzimarev
Copy link

I am using 3.3.1 and on both 4.6.1 and 4.6.2 it crashes after not being able to find System.Net.Http 4.1.1

@nblumhardt
Copy link
Member

Thanks for the note, @alexeyzimarev. I just created a fresh .NET 4.6.1 project and installed Serilog 2.4 + Serilog.Sinks.Seq 3.3.1, (unfortunately?) it seems to work perfectly:

image

The best I can come up with is perhaps you've changed the project's target framework version without uninstalling/reinstalling the package?

I'm running VS2017, latest patches. Are you using the same IDE version?

(If you are able to zip up a minimal project that reproduces the issue, feel free to email it through to nblumhardt@ either nblumhardt.com or getseq.net.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants