# "Common Language Runtime detected an invalid program." using NEST

**URL:** <https://discuss.elastic.co/t/common-language-runtime-detected-an-invalid-program-using-nest/224509>\
**Category:** Elasticsearch\
**Created:** [March 21, 2020, 5:24am UTC](https://discuss.elastic.co/t/common-language-runtime-detected-an-invalid-program-using-nest/224509 "2020-03-21T05:24:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nestrq](https://avatars.discourse-cdn.com/v4/letter/n/ebca7d/32.png) [@nestrq](https://discuss.elastic.co/u/nestrq)\
**Post date:** [March 21, 2020, 5:24am UTC](https://discuss.elastic.co/t/common-language-runtime-detected-an-invalid-program-using-nest/224509/1 "2020-03-21T05:24:17Z")

</div>

I have the exact same issue as the person in this locked thread: [Nest 6.6 getting InvalidProgramException sometimes](https://discuss.elastic.co/t/nest-6-6-getting-invalidprogramexception-sometimes/218058)

The only difference is that I am using NEST 6.3.1 with .NET Core 3.1. That post is closed after last mentioning a ticket that I am not able to follow up on, so I am making another to track this. This issue has just recently started having an impact for my microservice which is deployed in the cloud using kubernetes. We also have Elastic APM enabled. The first time I've experienced this is yesterday, so I am in the process of figuring out what may have changed, but the error seems to come from the NEST client. Here is the stack trace:

```auto
        at Elasticsearch.Net.Transport`1.RequestAsync[TResponse](HttpMethod method, String path, CancellationToken cancellationToken, PostData data, IRequestParameters requestParameters)
           at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
           at Elasticsearch.Net.Transport`1.RequestAsync[TResponse](HttpMethod method, String path, CancellationToken cancellationToken, PostData data, IRequestParameters requestParameters)
           at Elasticsearch.Net.ElasticLowLevelClient.DoRequestAsync[TResponse](HttpMethod method, String path, CancellationToken cancellationToken, PostData data, IRequestParameters requestParameters)
           at Elasticsearch.Net.ElasticLowLevelClient.CountAsync[TResponse](String index, String type, PostData body, CountRequestParameters requestParameters, CancellationToken ctx)
           at Nest.LowLevelDispatch.CountDispatchAsync[TResponse](IRequest`1 p, SerializableData`1 body, CancellationToken ct)
           at Nest.ElasticClient.Nest.IHighLevelToLowLevelDispatcher.DispatchAsync[TRequest,TQueryString,TResponse,TResponseInterface](TRequest request, CancellationToken cancellationToken, Func`3 responseGenerator, Func`4 dispatch)

```

---

<div class="post-metadata">

**Author:** ![nestrq](https://avatars.discourse-cdn.com/v4/letter/n/ebca7d/32.png) [@nestrq](https://discuss.elastic.co/u/nestrq)\
**Post date:** [March 25, 2020, 9:45pm UTC](https://discuss.elastic.co/t/common-language-runtime-detected-an-invalid-program-using-nest/224509/2 "2020-03-25T21:45:53Z")

</div>

How can I reply to the original topic? It's kind of absurd that I can't reach out to the people with knowledge of my exact same problem just last month.

---

<div class="post-metadata">

**Author:** ![nestrq](https://avatars.discourse-cdn.com/v4/letter/n/ebca7d/32.png) [@nestrq](https://discuss.elastic.co/u/nestrq)\
**Post date:** [March 26, 2020, 4:04pm UTC](https://discuss.elastic.co/t/common-language-runtime-detected-an-invalid-program-using-nest/224509/3 "2020-03-26T16:04:15Z")

</div>

bump to prevent closure

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 26, 2020, 4:54pm UTC](https://discuss.elastic.co/t/common-language-runtime-detected-an-invalid-program-using-nest/224509/4 "2020-03-26T16:54:20Z")

</div>

@Martijn_Laarman do you know?

---

<div class="post-metadata">

**Author:** ![Martijn\_Laarman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/martijn_laarman/32/4410_2.png) [@Martijn\_Laarman](https://discuss.elastic.co/u/Martijn_Laarman)\
**Post date:** [March 26, 2020, 5:26pm UTC](https://discuss.elastic.co/t/common-language-runtime-detected-an-invalid-program-using-nest/224509/5 "2020-03-26T17:26:32Z")

</div>

@nestrq can I bother you once more to open this as an issue on: [https://github.com/elastic/elasticsearch-net](https://github.com/elastic/elasticsearch-net). Would be the best place to coordinate this further.

Thank you for your persistence in keeping this alive and @dadoonet for pulling me in.

It would also help us if you are able to update to the latest version of the client to know if the problem persists.

---

<div class="post-metadata">

**Author:** ![nestrq](https://avatars.discourse-cdn.com/v4/letter/n/ebca7d/32.png) [@nestrq](https://discuss.elastic.co/u/nestrq)\
**Post date:** [March 26, 2020, 5:49pm UTC](https://discuss.elastic.co/t/common-language-runtime-detected-an-invalid-program-using-nest/224509/6 "2020-03-26T17:49:21Z")

</div>

@Martijn_Laarman thanks for your reply! I can certainly do that.

About upgrading the client, I thought the client we used was supposed to tie into the version of ES we are on - is that not the case? I can't update to 7.xx as we are on ES 6.xx.

---

<div class="post-metadata">

**Author:** ![Martijn\_Laarman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/martijn_laarman/32/4410_2.png) [@Martijn\_Laarman](https://discuss.elastic.co/u/Martijn_Laarman)\
**Post date:** [March 26, 2020, 6:06pm UTC](https://discuss.elastic.co/t/common-language-runtime-detected-an-invalid-program-using-nest/224509/7 "2020-03-26T18:06:40Z")

</div>

> I can't update to 7.xx as we are on ES 6.xx.

This is very true! I should have been more explicit and mentioned upgrading to the latest `6.x` minor:

> **[NEST 6.8.5](https://www.nuget.org/packages/NEST/6.8.5)**
>
> Strongly typed interface to Elasticsearch. Fluent and classic object initializer mappings of requests and responses. Uses and exposes Elasticsearch.Net

---

<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:** [April 23, 2020, 6:06pm UTC](https://discuss.elastic.co/t/common-language-runtime-detected-an-invalid-program-using-nest/224509/8 "2020-04-23T18:06:46Z")

</div>

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