question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Upgrade to version 3.0.0/3.1.0 causes FileNotFoundException (Newtonsoft assembly)

See original GitHub issue

Hi,

At first I thought this is APM package that is causing this issue but after upgrading/downgrading different packages for a day I found out that it is coverlet.collector that is causing it. The issue only shows up in docker container though, we’re using mcr.microsoft.com/dotnet/sdk:5.0-alpine image.

Exception 01 ===================================
Type: System.IO.FileNotFoundException
Source: Elastic.Apm.Report.Serialization.PayloadItemSerializer, Elastic.Apm, Version=1.7.1.0, Culture=neutral, PublicKeyToken=ae7400d2c189cf22
Message: Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified.
Trace:    at Elastic.Apm.Report.Serialization.PayloadItemSerializer..ctor(IConfigurationReader configurationReader)
   at Elastic.Apm.Report.PayloadSenderV2..ctor(IApmLogger logger, IConfigSnapshot config, Service service, System system, IApmServerInfo apmServerInfo, HttpMessageHandler httpMessageHandler, String dbgName, Boolean isEnabled)
   at Elastic.Apm.AgentComponents..ctor(IApmLogger logger, IConfigurationReader configurationReader, IPayloadSender payloadSender, IMetricsCollector metricsCollector, ICurrentExecutionSegmentsContainer currentExecutionSegmentsContainer, ICentralConfigFetcher centralConfigFetcher, IApmServerInfo apmServerInfo)
   at Elastic.Apm.AgentComponents..ctor(IApmLogger logger, IConfigurationReader configurationReader, IPayloadSender payloadSender)
   at Elastic.Apm.AspNetCore.ApmMiddlewareExtension.UseElasticApm(IApplicationBuilder builder, IConfiguration configuration, IDiagnosticsSubscriber[] subscribers)
   at Elastic.Apm.NetCoreAll.ApmMiddlewareExtension.UseAllElasticApm(IApplicationBuilder builder, IConfiguration configuration)
   at Organisation.Infrastructure.FrameworkExtensions.UseElasticApmMetricsConfigured(IApplicationBuilder app, IConfiguration configuration, IWebHostEnvironment webHostEnvironment) in /app/src/Organisation/Infrastructure/FrameworkExtensions.cs:line 93
   at Organisation.Startup.Configure(IApplicationBuilder app, ILogger`1 logger) in /app/src/Organisation/Startup.cs:line 108
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass15_0.<UseStartup>b__1(IApplicationBuilder app)
   at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
Location: 
Method: Void .ctor(Elastic.Apm.Config.IConfigurationReader) (0, 0)

More details here:

https://github.com/elastic/apm-agent-dotnet/issues/1117

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:26

github_iconTop GitHub Comments

2reactions
billybragacommented, Aug 16, 2021

I solved my problem by adding IsPublishable=false in csproj of test projects (instead of removing the test dlls in CI/CD before building final docker image with dlls).

As for running dotnet test ..., this has never been a problem.

I still think coverlet shouldn’t add a Newtonsoft dll directly instead of relying on nuget dependencies, but personally I’m not having problems anymore with that since using IsPublishable=false like stated above.

2reactions
billybragacommented, Jan 19, 2021

I believe the issue is coverlet.collector nuget package doesn’t specify dependencies, but still includes Newtonsoft.Json.dll.

From the detailed output publish, I see this :

Copying file from "/home/--ME--/.nuget/packages/coverlet.collector/3.0.1/build/netstandard1.0/Newtonsoft.Json.dll" to "/home/local/--ME--/dev/projects/Xxx/tests/Xxx.Tests.Lib/bin/Release/net5.0/publish/Newtonsoft.Json.dll".

Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not load file or assembly 'Newtonsoft.Json' or one of ...
I have tried the steps by Oleg, and they worked for my same situation. Steps: Run update-package Newtonsoft. Json -reinstall in Package Manager....
Read more >
13.0.1 causes file not found exception when assembly gets ...
1 I get a FileNotFoundException on this [1] constructor as .NET attempts to load the Newtonsoft.Json dll. The message states cannot find an ......
Read more >
Solved: Could not load file or assembly 'Newtonsoft.Json
Solved: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0' when i try to login power bi gateway.
Read more >
Newtonsoft Json package
I believe it's using the latest version of newtonsoft json. The spelling mistake has been fixed and will be included in the next...
Read more >
Conflict between Asset's Newtonsoft and ...
dll plugin and i get an error that says: "PrecompiledAssemblyException: Multiple precompiled assemblies with the same name Newtonsoft.Json.dll ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found