Skip to content

Commit

Permalink
Load system.text.json with any major version
Browse files Browse the repository at this point in the history
  • Loading branch information
nvborisenko committed Jul 11, 2024
1 parent 08eddf1 commit 4fc5368
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/ReportPortal.Client/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,32 @@
using ReportPortal.Client.Resources;
using System;
using System.Net.Http;
using System.Reflection;

namespace ReportPortal.Client
{
/// <inheritdoc cref="IClientService"/>
public partial class Service : IClientService, IDisposable
{
static Service()
{
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
}

private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
if (args.Name.StartsWith("System.Text.Json", StringComparison.OrdinalIgnoreCase))
{
return Assembly.Load("System.Text.Json");
}
else if (args.Name.StartsWith("System.Text.Encodings.Web", StringComparison.OrdinalIgnoreCase))
{
return Assembly.Load("System.Text.Encodings.Web");
}

return null;
}

private readonly HttpClient _httpClient;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.Json;

namespace ReportPortal.Shared.Configuration.Providers
Expand All @@ -10,6 +12,21 @@ namespace ReportPortal.Shared.Configuration.Providers
/// </summary>
public class JsonFileConfigurationProvider : IConfigurationProvider
{
static JsonFileConfigurationProvider()
{
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
}

private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
if (args.Name.StartsWith("System.Text.Json", StringComparison.OrdinalIgnoreCase))
{
return Assembly.Load("System.Text.Json");
}

return null;
}

private readonly string _delimeter;
private readonly string _filePath;
private readonly bool _optional;
Expand Down

0 comments on commit 4fc5368

Please sign in to comment.