Closed
Description
NEST/Elasticsearch.Net version:
7.4.2
Elasticsearch version:
7.3.1
Description of the problem including expected versus actual behavior:
If I set a class that inherits Exception to the value of Dictionary<string, object>
and post it to index, the following InvalidCastException is thrown.
Message: Unable to cast object of type 'Elasticsearch.Net.ExceptionFormatter' to type 'Elasticsearch.Net.Utf8Json.IJsonFormatter`1 [System.NullReferenceException]'.
StackTrace: Elasticsearch.Net.ExceptionFormatterResolver.GetFormatter<T>()
Elasticsearch.Net.ElasticsearchNetFormatterResolver.InnerResolver.GetFormatter.AnonymousMethod__4_0<T>(System.Type)
System.Collections.Concurrent.ConcurrentDictionary<TKey, TValue>.GetOrAdd(TKey, System.Func<TKey, TValue>)
Elasticsearch.Net.ElasticsearchNetFormatterResolver.InnerResolver.GetFormatter<T>()
I hope it can be sent without problems.
Steps to reproduce:
Since it occurs at the time of serializing PostData
, i attach the reproduction code
var settings = new ConnectionConfiguration();
var dic = new Dictionary<string, object>()
{
["Exception"] = new NullReferenceException(),
};
var data = PostData.Serializable(dic);
using var ms = new MemoryStream();
data.Write(ms, settings); // Exception is thrown!!