# Error ElasticSearch: Error while sending log messages Exception: Elasticsearch.Net.UnexpectedElasticsearchClientException: Failed to serialize anonymous type: System.RuntimeType

**URL:** <https://discuss.elastic.co/t/error-elasticsearch-error-while-sending-log-messages-exception-elasticsearch-net-unexpectedelasticsearchclientexception-failed-to-serialize-anonymous-type-system-runtimetype/368194>\
**Category:** Elasticsearch\
**Created:** [October 3, 2024, 12:53pm UTC](https://discuss.elastic.co/t/error-elasticsearch-error-while-sending-log-messages-exception-elasticsearch-net-unexpectedelasticsearchclientexception-failed-to-serialize-anonymous-type-system-runtimetype/368194 "2024-10-03T12:53:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fatbardh](https://avatars.discourse-cdn.com/v4/letter/f/cc9497/32.png) [@Fatbardh](https://discuss.elastic.co/u/Fatbardh)\
**Post date:** [October 3, 2024, 12:53pm UTC](https://discuss.elastic.co/t/error-elasticsearch-error-while-sending-log-messages-exception-elasticsearch-net-unexpectedelasticsearchclientexception-failed-to-serialize-anonymous-type-system-runtimetype/368194/1 "2024-10-03T12:53:58Z")

</div>

**NEST/Elasticsearch.Net version** : 7.17.0

**NLog version** : 5.0.3

**Platform** : .NET Core / .NET5 / NET6

Exception gist: [Error ElasticSearch: Error while sending log messages Exception: Elasticsearch.Net.UnexpectedElasticsearchClientException: Failed to serialize anonymous type: System.RuntimeType · GitHub](https://gist.github.com/fhimaj/6f936956be2a348fb140b9697e302b7b)

Exception occurs on different .net projects and it happens randomly after starting to log to an elasticsearch cluster. It does not happen while writing to a local file. Similar exceptions with suggestions to try to fix it by modifying NLog configuration with setting "MaxRecursionLimit=1" did not work, and it was suggested that this is a NEST/Elasticsearch client issue: [Elasticsearch.Net.UnexpectedElasticsearchClientException: Failed to serialize anonymous type when writting to NLog · Issue #182 · markmcdowell/NLog.Targets.ElasticSearch · GitHub](https://github.com/markmcdowell/NLog.Targets.ElasticSearch/issues/182)  
[Error ElasticSearch: Error while sending log messages Exception: Elasticsearch.Net.UnexpectedElasticsearchClientException: Failed to serialize anonymous type: System.RuntimeType · Issue #5616 · NLog/NLog · GitHub](https://github.com/NLog/NLog/issues/5616)

Thank you in advance

---

<div class="post-metadata">

**Author:** ![nfeekery](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nfeekery/32/117349_2.png) [@nfeekery](https://discuss.elastic.co/u/nfeekery)\
**Post date:** [October 4, 2024, 8:54am UTC](https://discuss.elastic.co/t/error-elasticsearch-error-while-sending-log-messages-exception-elasticsearch-net-unexpectedelasticsearchclientexception-failed-to-serialize-anonymous-type-system-runtimetype/368194/2 "2024-10-04T08:54:37Z")

</div>

From #Elastic Search to #Elasticsearch

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 1, 2024, 8:54am UTC](https://discuss.elastic.co/t/error-elasticsearch-error-while-sending-log-messages-exception-elasticsearch-net-unexpectedelasticsearchclientexception-failed-to-serialize-anonymous-type-system-runtimetype/368194/3 "2024-11-01T08:54:44Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
