Closed saliehendricks closed 1 year ago
Thanks for reporting @saliehendricks.
System.TypeInitializationException HResult=0x80131534 Message=The type initializer for 'Elastic.CommonSchema.Serialization.JsonConfiguration' threw an exception.
Inner Exception 1: FileNotFoundException: Could not load file or assembly 'System.Text.Encodings.Web, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
Elastic.CommonSchema.BenchmarkDotNetExporter 1.5.1 has a dependency on Elastic.CommonSchema 1.5.1, which in turn has a dependency on System.Text.Json (>= 4.7.0), which the latest version to match the version constraint (5.0.2) has the dependency on System.Text.Encodings.Web (>= 5.0.1). Are all the dependencies restored and up to date in the repository?
I just tried to replicate this by following the provided steps, but was unable to replicate. the benchmarks are successfully sent to Elasticsearch. Here's what I have
In Program.cs
using System;
using System.Security.Cryptography;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Running;
using Elastic.CommonSchema.BenchmarkDotNetExporter;
namespace EcsDotNet142
{
class Program
{
static void Main(string[] args)
{
var options = new ElasticsearchBenchmarkExporterOptions("http://localhost:9200")
{
GitBranch = "externally-provided-branch",
GitCommitMessage = "externally provided git commit message",
GitRepositoryIdentifier = "repository"
};
var exporter = new ElasticsearchBenchmarkExporter(options);
var config = ManualConfig.Create(DefaultConfig.Instance);
config.Add(exporter);
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, config);
}
}
public class Md5VsSha256
{
private readonly SHA256 _sha256 = SHA256.Create();
private readonly MD5 _md5 = MD5.Create();
private byte[] _data;
[Params(1000, 10000)]
public int N;
[GlobalSetup]
public void Setup()
{
_data = new byte[N];
new Random(42).NextBytes(_data);
}
[Benchmark]
public byte[] Sha256() => _sha256.ComputeHash(_data);
[Benchmark]
public byte[] Md5() => _md5.ComputeHash(_data);
}
}
and in EcsDotNet142.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Elastic.CommonSchema.BenchmarkDotNetExporter" Version="1.5.1" />
</ItemGroup>
</Project>
The results are successfully sent to Elasticsearch
{
"took" : 4,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 4,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "benchmarks-dotnet-2021-01-01",
"_type" : "_doc",
"_id" : "vBBrsHkBC3aXDFAhmKaM",
"_score" : 1.0,
"_source" : {
"agent" : {
"git" : {
"branch_name" : "externally-provided-branch",
"commit_message" : "externally provided git commit message",
"repository" : "repository"
},
"language" : {
"jit_info" : "RyuJIT",
"dot_net_sdk_version" : "5.0.202",
"benchmark_dot_net_caption" : "BenchmarkDotNet",
"has_ryu_jit" : true,
"build_configuration" : "RELEASE",
"benchmark_dot_net_version" : "0.12.0",
"version" : ".NET Core 3.1.14 (CoreCLR 4.700.21.16201, CoreFX 4.700.21.16208)"
},
"type" : "Elastic.CommonSchema.BenchmarkDotNetExporter",
"version" : "1.5.1+4d79199d75c989bc6e1ec19727faa3db58e6058b"
},
"os" : {
"name" : "Windows",
"version" : "Windows 10.0.19042",
"platform" : "windows"
},
"message" : null,
"benchmark" : {
"lower_outliers" : [
4236.067962646484
],
"q1" : 4296.057510375977,
"confidence_interval" : {
"margin" : 61.83926483651583,
"level" : 12,
"mean" : 4322.973280686599,
"lower" : 4261.1340158500825,
"n" : 13,
"standard_error" : 14.321967130061191
},
"percentiles" : {
"p0" : 4236.067962646484,
"p67" : 4330.403869628906,
"p25" : 4297.650909423828,
"p100" : 4458.814239501953,
"p90" : 4367.1337890625,
"p80" : 4332.4237060546875,
"p50" : 4315.187072753906,
"p85" : 4341.626281738281,
"p95" : 4408.907470703125
},
"q3" : 4332.248687744141,
"all_outliers" : [
4236.067962646484,
4458.814239501953
],
"interquartile_range" : 36.19117736816406,
"max" : 4458.814239501953,
"upper_fence" : 4386.535453796387,
"standard_deviation" : 51.63858685294546,
"kurtosis" : 4.405886040660377,
"n" : 13,
"standard_error" : 14.321967130061191,
"min" : 4236.067962646484,
"median" : 4315.187072753906,
"upper_outliers" : [
4458.814239501953
],
"variance" : 2666.5436521691913,
"mean" : 4322.973280686599,
"lower_fence" : 4241.7707443237305,
"skewness" : 1.0739353248970622
},
"@timestamp" : "2021-05-28T00:41:51.5465926+00:00",
"host" : {
"chronometer_frequency_hertz" : 10000000,
"hardware_timer_kind" : "Unknown",
"physical_processor_count" : 1,
"logical_core_count" : 12,
"in_docker" : false,
"processor_name" : "Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz",
"has_attached_debugger" : true,
"physical_core_count" : 6,
"architecture" : "X64"
},
"log.level" : null,
"event" : {
"duration" : 70965619300,
"measurement_stages" : [
{
"operations" : 1,
"iteration_mode" : "Overhead",
"iteration_stage" : "Jitting"
},
{
"operations" : 1,
"iteration_mode" : "Workload",
"iteration_stage" : "Jitting"
},
{
"operations" : 16,
"iteration_mode" : "Workload",
"iteration_stage" : "Pilot"
},
{
"operations" : 131072,
"iteration_mode" : "Overhead",
"iteration_stage" : "Warmup"
},
{
"operations" : 131072,
"iteration_mode" : "Overhead",
"iteration_stage" : "Actual"
},
{
"operations" : 131072,
"iteration_mode" : "Workload",
"iteration_stage" : "Warmup"
},
{
"operations" : 131072,
"iteration_mode" : "Workload",
"iteration_stage" : "Actual"
},
{
"operations" : 131072,
"iteration_mode" : "Workload",
"iteration_stage" : "Result"
}
],
"job_config" : {
"jit" : "Default",
"launch" : {
"unroll_factor" : 0,
"max_iteration_count" : 0,
"launch_count" : 0,
"iteration_count" : 0,
"run_strategy" : "Throughput",
"iteration_time_in_milliseconds" : 0,
"warm_count" : 0,
"max_warmup_iteration_count" : 0,
"invocation_count" : 0,
"min_warmup_iteration_count" : 0,
"min_iteration_count" : 0
},
"id" : "Default",
"gc" : {
"heap_affinitize_mask" : 0,
"server" : false,
"no_affinitize" : false,
"allow_very_large_objects" : false,
"retain_vm" : false,
"cpu_groups" : false,
"concurrent" : false,
"heap_count" : 0,
"force" : false
},
"platform" : "AnyCpu"
},
"original" : "Md5VsSha256.Sha256: DefaultJob [N=1000]",
"method" : "EcsDotNet142.Md5VsSha256.Sha256(N: 1000)",
"module" : "EcsDotNet142",
"description" : "Sha256",
"action" : "Sha256",
"category" : [
"EcsDotNet142.Md5VsSha256-20210528-104039"
],
"type" : [
"Md5VsSha256"
],
"parameters" : "N=1000",
"repetitions" : {
"measured" : 131072,
"warmup" : 131072
}
}
}
}
]
}
}
Are you able to share a small example that replicates the finding?
Hi @russcam,
Thanks for clarifying the dependency chain and giving it a test. Will put together a sample (if I can recreate it!).
Just for my own record, my package references were as folllows:
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
<PackageReference Include="BenchmarkDotNet.Annotations" Version="0.12.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
<PackageReference Include="ServiceStack.Text" Version="5.11.0" />
<PackageReference Include="System.Text.Json" Version="5.0.2" />
ServiceStack.Text does not share any common dependencies. Microsoft.Extensions.Configuration.Json depends on System.Text.Json >=5.0.0 - me thinks the issue might be here.
Microsoft.Extensions.Configuration.Json depends on System.Text.Json >=5.0.0 - me thinks the issue might be here.
Possibly; I would expect dependency resolution to pick the higher version though, and for it to "just work", though expectations don't always match reality!
Closing this because we were unable to reproduce and have not seen this error since.
Thanks for bringing this to our attention though @saliehendricks :+1:
ECS integration/library project(s) (e.g. Elastic.CommonSchema.Serilog): Elastic.CommonSchema.BenchmarkDotNetExporter ECS schema version (e.g. 1.4.0): 1.5.1 ECS .NET assembly version (e.g. 1.4.2): 1.5.1 Elasticsearch version (if applicable): ES Cloud 7 .NET framework / OS: netcore 3.1
Description of the problem, including expected versus actual behavior: Serialization exception after benchmarks have been constructed just before posting to ES
Specifically on this line: https://github.com/elastic/ecs-dotnet/blob/725c4e706d93216dd379898675ace30357b0dd36/src/Elastic.CommonSchema/Base.Serialization.cs#L56
System.TypeInitializationException HResult=0x80131534 Message=The type initializer for 'Elastic.CommonSchema.Serialization.JsonConfiguration' threw an exception.
Inner Exception 1: FileNotFoundException: Could not load file or assembly 'System.Text.Encodings.Web, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
Steps to reproduce:
I managed to fix this by cloning the repo and updating all System.Text.Json reference to 5.0.2 and the problem went away. I believe it is just the fact that I referenced from Nuget rather than the version.