Unable to initialize ConnectionConfiguration in certain conditions
See original GitHub issueNEST/Elasticsearch.Net 7.0+:
Elasticsearch any:
Indirect initialization of ConnectionConfiguration throws AmbiguousMatchException: When an instance of ConnectionConfiguration is being initialized the static constructor is invoked indirectly by accessing to read-only static property to hold default user agent. By call stack it crash when accessing to RuntimeInformation.FrameworkDescription
[AmbiguousMatchException: Multiple custom attributes of the same type found.]
System.Attribute.GetCustomAttribute(Assembly element, Type attributeType, Boolean inherit) +119
Elasticsearch.Net.RuntimeInformation.get_FrameworkDescription() +96
Elasticsearch.Net.ConnectionConfiguration..cctor() +402
[TypeInitializationException: The type initializer for 'Elasticsearch.Net.ConnectionConfiguration' threw an exception.]
We was able to localize the bug on RuntimeInformation
public static string FrameworkDescription
{
get
{
if (_frameworkDescription == null)
{
var assemblyFileVersionAttribute =
(AssemblyFileVersionAttribute)typeof(object).GetTypeInfo().Assembly.GetCustomAttribute(typeof(AssemblyFileVersionAttribute));
_frameworkDescription = $".NET Framework {assemblyFileVersionAttribute.Version}";
}
return _frameworkDescription;
}
}
In unknown conditions depends on .NET Framework returns more than one attribute AssemblyFileVersionAttribute and Assembly.GetCustomAttribute throws an exception.
According to our investigation both attributes come from the same module but has different version of the file
System.Reflection.AssemblyFileVersionAttribute file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll 4.0.30319 System.Reflection.AssemblyFileVersionAttribute file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll 2.0.0.205
The first one always has .NET Framework version but the second one indicates version of something unknown for us 2.0.0.205
Issue was introduced in 7.x according to the sources https://github.com/elastic/elasticsearch-net/blob/7.x/src/Elasticsearch.Net/Api/RuntimeInformation.cs
Steps to reproduce:
- Initialize Elasticsearch client on web application
It can be reproduced only on some Windows Server and relevant only to web application. On the same machine console application behaves as expected and .NET Framework objects has single attribute, that strange.
Our research was done on Windows Server 2012 & Windows Server 2012 R2 regardless of which build of .NET 4.7.2 is used.
We continue investigation to isolate it and find out which settings or conditions lead to have more than one attribute for system objects. It’s not new issue with .NET
Add User-Agent string to API calls to Elasticsearch #3784: With PR https://github.com/elastic/elasticsearch-net/pull/3784
As a suggested fix it’s to read all attributes and filter them instead of attempt to read a single.
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (2 by maintainers)
Top GitHub Comments
Got the same error in Nest 6.8.3 after windows update. Any clue how to fix it without upgrading Nest to version with the fix? Or is there any chance you can release this fix in 6.x?
That works too, and a little more succinct 🙂