MindscapeHQ / raygun4net

Raygun provider for .NET
https://raygun.com
MIT License
126 stars 93 forks source link

StackOverflowException with .NET Core client #392

Closed andrewlock closed 6 years ago

andrewlock commented 6 years ago

This took me a while to pin down, but the SimpleJson.cs class used in Mindscape.Raygun4Net.NetCore.Common does not seem to be able to serialize Types correctly - instead it throws a StackOverflowException and crashes the process.

Here's a simple repro:

var data = new Dictionary<string, object> {{"Error", typeof(SimpleJson)}}; // userdata contains a Type

var message = RaygunMessageBuilder.New(new RaygunSettings { ApiKey = "" })
    .SetUserCustomData(data)
    .Build();

SimpleJson.SerializeObject(message); // throws StackOverflowExcepion and crashes the process

Maintaining your own JSON serializer seems a little pointless here, especially when you're including Newtonsoft.Json in Mindscape.Raygun4Net.NetCore anyway... It seems like using Newtonsoft.JSON would be the safest option.

Alternatively, update SimpleJson to handle serializing Types by calling .AssemblyQualifiedName on them, instead of trying to do a deep serialization (which I assume is what's calling the recurrsion)

j5alive commented 6 years ago

@andrewlock Thanks for reporting this, I'll get the team to have a look into this issue soon.

I'm not sure how or why Newtonsoft.Json was added in a dependency as nothing in the projects uses it, hence why SimpleJson is used.

j5alive commented 6 years ago

Version 6.0.1 of Mindscape.Raygun4Net.NetCore and Mindscape.Raygun4Net.AspNetCore are now available on nuget.

https://www.nuget.org/packages/Mindscape.Raygun4Net.NetCore/ https://www.nuget.org/packages/Mindscape.Raygun4Net.AspNetCore/