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

Adding Serilog to an existing project: Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation #1215

Closed
3 of 7 tasks
rizamarhaban opened this issue Sep 13, 2018 · 8 comments

Comments

@rizamarhaban
Copy link

A few questions before you begin:

Is this an issue related to the Serilog core project or one of the sinks or community projects. This issue list is intended for Serilog core issues. If this issue relates to a sink or related project, please log on the related repository. Please use Gitter chat and Stack Overflow for discussions and questons.

Does this issue relate to a new feature or an existing bug?

  • Bug
  • New Feature

What version of Serilog is affected? Please list the related NuGet package.
<package id="Serilog" version="2.7.1" targetFramework="net471" /> <package id="Serilog.Sinks.Console" version="3.1.1" targetFramework="net471" /> <package id="Serilog.Sinks.File" version="4.0.0" targetFramework="net471" />

What is the target framework and operating system? See target frameworks & net standard matrix.

  • netCore 2.0
  • netCore 1.0
  • 4.7
  • 4.6.x
  • 4.5.x

OS: Windows 10

Please describe the current behavior?
When executing this line:

Host = WebHost.CreateDefaultBuilder()
        .UseUrls($"http://{IpAddress}:55555", $"http://{hostName}:55555")
        .UseContentRoot(pathToContentRoot)
        .UseStartup<Startup>()
        .Build();

Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll [09:26:05 INF] WebHost.CreateDefaultBuilder(): Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. [09:26:05 INF] InnerException: Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

Please describe the expected behavior?
Removing Serilog all together was fine. I assume this is because Serilog package was added.

If the current behavior is a bug, please provide the steps to reproduce the issue and if possible a minimal demo of the problem

  1. Create a WPF Application with .NET Framework 4.7.1.
  2. Add ASP.NET Core 2.0 Web API in WPF.
  3. Run the ASP.NET Core service under WPF.
    This all works without any issue without Serilog. However, I would like to use Serilog rather than my built-in too simple logger. And this is cause an issue.
@nblumhardt
Copy link
Member

Add ASP.NET Core 2.0 Web API in WPF

:-)

Hi Riza! Thanks for getting in touch.

Unfortunately most of these kinds of issues end up being machine-specific, or caused by bugs/limitations/intended behavior in Visual Studio, NuGet or dotnet. It's rare that we find the cause in the Serilog package itself.

It's also usually hard to reproduce the exact setup that produces the error - so we don't generally try, unless an error is being reported widely.

If you're able to dig in deeper, and figure out whether the problem is the Serilog package itself, or just something the SDK is doing incorrectly based on Serilog or one of its framework dependencies, the help would be appreciated. We're eager to fix any issues that can be addressed by Serilog directly, and will happily commit time to that if the cause is found.

Hope this helps, and please keep us in the loop if you find additional information.

Nick

@jbp17
Copy link

jbp17 commented Oct 5, 2018

I had the same issue. I think it is still a Serilog related issue. Serilog is dependent on System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0. But current version for System.Runtime.InteropServices.RuntimeInformation, v4.3. So System.Runtime.InteropServices.RuntimeInformation, v4.0 is not available, so the program can't locate it. Serilog should update its package to using System.Runtime.InteropServices.RuntimeInformation, v4.3.

@dewelloper
Copy link

dewelloper commented Apr 22, 2019

Also, i do the same issure its very clear interesting with serilog!
Iam using .net core 2.2 with serilog latest version and it giving me this error by project starting same like above

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
          WebHost.CreateDefaultBuilder(args)
              //.UseSetting("https_port", "6379")
              .UseStartup<Startup>()
              .UseSerilog();

Error:

Could not load file or assembly 'Serilog.AspNetCore, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10'. The system cannot find the file specified.

Explanation!: I have always installed lastest version, that is .net core 2 nowdays. Not difficult to reproduce the error. You can create a project with 2 layers with a standart library 2.0 and a webapi. That api will call to the lib project and will use serilog in one of them or both and than it will throw this error!!!

@zachrybaker
Copy link

zachrybaker commented Aug 19, 2020

Could not load file or assembly 'Serilog.AspNetCore, Version=2.0.0.0

Interesting @dewelloper did you resolve this?

I currently ran into this adding it to an OLD ASP.NET 4.7.2 Web forms app. The web app doesn't use/reference serilog, but a dependent logging project does. The dependent project is .NetStandard 2.0. And I get:

FileNotFoundException: Could not load file or assembly 'Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10'

.....which is not even the version that is installed (2.9).

...this could be why:

Version Information: Microsoft .NET Framework Version:**4.0.**30319; ASP.NET Version:4.8.4075.0

from the serilog 2.0 upgrade guide:

Serilog 2.0 no longer supports .NET 4.0. Applications targeting .NET 4.0 can continue to use the Serilog 1.5 series of packages or update to .NET 4.5.2.

It seems to me that the versioning is goofed in my app, as it is supposed to be .Net Framework 4.7.2.

For me I am using serilog successfully in many projects, mostly .Net Core, so I have created my own convenience nuget packages to roll it up with the sinks and modules I like. And I also use Serilog in at least one framework console app, which also contains a .NetStandard 2.0 library which also uses Serilog (the library has its own separate logging setup, to log separately). Again, no problems there.

@skomis-mm
Copy link
Contributor

Hi @zachrybaker ,

If you reference netstandard project from old style csproj you won't get Serilog.dll in output (check the bin folder) because of indirection dependency to Serilog. Try to add Serilog package to your web forms project.

@dewelloper
Copy link

@zachrybaker i remember that I converted library version to caller project version. On my position it's appeared difficult but to making it simple than fixing library

@zachrybaker
Copy link

zachrybaker commented Aug 19, 2020 via email

@gmckelvey233
Copy link

@zachrybaker ,

If you reference netstandard project from old style csproj you won't get Serilog.dll in output (check the bin folder) because of indirection dependency to Serilog. Try to add Serilog package to your web forms project.

Thank you so much for this, it made me realize I needed to add a post-build event that copied the serilog dll's to the actual directory my program runs.

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

7 participants