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.

Unable to initialize ConnectionConfiguration in certain conditions

See original GitHub issue

NEST/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:

  1. 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:closed
  • Created 4 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mozerovcommented, Feb 10, 2020

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?

0reactions
russcamcommented, Dec 17, 2019

You can use Max instead of sorting in descending order and then taking the first element.

That works too, and a little more succinct 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

SSIS - Error: Failed to acquire connection
A situation caused an error. I need to fix that. Error -. [Execute SQL Task] Error: Failed to acquire connection "MyDBConnection".
Read more >
In Jmeter Unable to make JDBC Connection to SSMS ...
I am trying to make a JDBC connection to SQL server but I am getting this error Cannot create PoolableConnectionFactory (The driver could ......
Read more >
Troubleshoot Analytics Extension Connections
Tableau failed to initialize a secure environment for this given External Service configuration. Check to see that the host and port are correct,...
Read more >
Dataflow connection configuration not working
I have a dataflow with a few queries that connect to an Oracle source. It was working fine for a while but after...
Read more >
Task 4: Verify the connection configuration
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/ . In the navigation pane, choose Instances. Choose the EC2 instance that you selected to ...
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