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.

Newtonsoft.Json failed to load

See original GitHub issue

Please mark the type framework used:

  • ASP.NET MVC
  • ASP.NET Web API (OWIN)
  • ASP.NET Core
  • WPF
  • WinForms
  • Xamarin
  • Other:

Please mark the type of the runtime used:

  • .NET Framework
  • Mono
  • .NET Core
  • Version: runtime is 4.8 but project is built to 4.7.2

Please mark the NuGet packages used:

  • Sentry
  • Sentry.Serilog
  • Sentry.NLog
  • Sentry.Log4Net
  • Sentry.Extensions.Logging
  • Sentry.AspNetCore
  • Version: 2.0.1

No log entries sent to Sentry.

Newtonsoft.Json failed to load

Debugger stopped at HttpTransport.cs line 69 with

System.IO.FileNotFoundException
  HResult=0x80070002
  Message=Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
  Source=Sentry
  StackTrace:
   at Sentry.Internal.JsonSerializer..cctor() in C:\projects\sentry-dotnet\src\Sentry\Internal\JsonSerializer.cs:line 9

I use the latest version of Newtonsoft.Json in an AutoCAD plugin and need to redirect the bindings because AutoCAD is a whole other universe of DLL hell. The Sentry CSPROJ file looks like …

<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
    <PackageReference Include="Newtonsoft.Json" Version="6.0.8" />
    <Reference Include="System.Web" />
  </ItemGroup>
  <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
    <PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
  </ItemGroup>

… changing the net461 section to "Newtonsoft.Json" Version="12.0.3" and building it locally worked for me (that’s the version of JSON.Net I use in my app).

Sentry debug log …

5/02/2020 3:09:17 PM -    Info: Capturing event. 
5/02/2020 3:09:17 PM -   Debug: Running main event processor on: Event [redacted]
5/02/2020 3:09:17 PM -   Debug: Creating SentryStackTrace. isCurrentStackTrace: True. 
5/02/2020 3:09:17 PM -   Debug: Event queued up. 
5/02/2020 3:09:17 PM -   Debug: Configuring the scope. 
5/02/2020 3:09:36 PM -   Debug: Event [redacted]in-flight to Sentry. #1 in queue. 
5/02/2020 3:09:39 PM -   Error: Error while processing event [redacted]: System.TypeInitializationException: The type initializer for 'Sentry.Internal.JsonSerializer' threw an exception. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: element
   at System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit)
   at System.Attribute.GetCustomAttribute(Assembly element, Type attributeType, Boolean inherit)
   at System.Reflection.CustomAttributeExtensions.GetCustomAttribute[T](Assembly element)
   --- End of inner exception stack trace ---
   at Sentry.Internal.JsonSerializer.SerializeObject[T](T object)
   at Sentry.Internal.Http.HttpTransport.CreateRequest(SentryEvent event)
   at Sentry.Internal.Http.HttpTransport.<CaptureEventAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
   at Sentry.Internal.BackgroundWorker.<WorkerAsync>d__18.MoveNext(). #1 in queue. 
5/02/2020 3:09:39 PM -   Debug: Configuring the scope. 

Not sure if this is a Sentry bug or just plain bad luck DLL hell and this workaround is the fix. It all worked fine until recently, I haven’t been able to trace the commit that broke it. The closest clues I can find is a different project that had the same problems when I updated … I attached a zip of the packages before and after from the commit I suspect broke things (Errors were logged locally so I can track when the first one didn’t go). Significant changes listed, diff the files to see what really happened. Packages-before-after.zip

  • Newtonsoft.Json 12.0.1 to 12.0.3
  • Serilog 2.8.0 to 2.9.0
  • System.Collections.Immutable 1.5.0 to 1.7.0 (Google that DLL, it’s pretty fragile)
  • System.Reflection.Metadata 1.6.0 to 1.8.0

I see the Sentry CSPROJ file has not changed in a long time and neither has mine, really. No idea why it all blew up. If nothing else I hope this helps someone if it’s not a thing you can fix at Sentry.

Cheers

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
bruno-garciacommented, Feb 6, 2020

@CADbloke The dependencies listed are the minimum required by the SDK, we try to keep dependencies requirement to a lower value.

This doesn’t stop you from using binding redirects to depend on a higher version. So it should be OK for you point to 12.0.3 via binding redirects alone, without having to change the dependencies of Sentry package.

I see you removed netstandard2.0 from your fork. If you are depending on Sentry’s package directly from a .NET Framework app, that target is really a no-op. When resolving dependencies it picks the relevant one and ignores all the rest. If you depend on it from a .NET Standard library (like some business logic library you have) it could be picking the .NET Standard one instead of the .NET Framework one.

0reactions
CADblokecommented, Feb 8, 2020

@bruno-garcia It’s a mystery to me too. I tried building versions from October and they failed too. I know I have received Sentry events from builds in December so perhaps it is something to do with a .NET framework update or something external like that. I may never know. The local Sentry build fixed it and I have already blown a day or so trying to track it down. Perhaps the binding redirect for my app only works one level deep, Sentry is loaded by my DLL which is loaded by the AutoCAD runtime. I can’t set biding redirects directly against AutoCAD because it would probably break AutoCAD, often considered an unattractive move.

Bloody AutoCAD!

Closing because it’s the edgiest of edge-cases and I found a reliable solution and it’s no fault of Sentry’s.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not load file or assembly 'Newtonsoft.Json, Version= ...
The error means .NET couldn't find the Json.NET library. Do you have it installed? – TypeIA. Mar 19, 2014 at 13:24.
Read more >
Solved: Could not load file or assembly 'Newtonsoft.Json
1.Delete Newtonsoft.Json dll from bin folder if any. · 2.If you are using web application project go to webconfig and remove these assembly ......
Read more >
Could not load file or assembly 'Newtonsoft.Json' - Top 3 ...
This error mainly occurs when the DNN website has an incorrect version of the Newtonsoft.Json package in its configuration. At Bobcares, we ...
Read more >
VS : How to solve Could not load file or assembly ...
In my case, the problem was caused by Visual Studio, which adds the old 6.0.4 Newtonsoft.Json package when creating the ASP.NET MVC project, ......
Read more >
Could not load file or assembly 'Newtonsoft.Json with the ...
Hello, While developing a Dll with visual studio in WPF and VB (Framework 4.8) and using Newtonsoft.Json.13.0.1 as a reference, ...
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