# Nest 6.6 getting InvalidProgramException sometimes

**URL:** <https://discuss.elastic.co/t/nest-6-6-getting-invalidprogramexception-sometimes/218058>\
**Category:** Elasticsearch\
**Created:** [February 5, 2020, 9:24pm UTC](https://discuss.elastic.co/t/nest-6-6-getting-invalidprogramexception-sometimes/218058 "2020-02-05T21:24:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjessee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mjessee/32/62153_2.png) [@mjessee](https://discuss.elastic.co/u/mjessee)\
**Post date:** [February 5, 2020, 9:24pm UTC](https://discuss.elastic.co/t/nest-6-6-getting-invalidprogramexception-sometimes/218058/1 "2020-02-05T21:24:55Z")

</div>

We're running a microservice, using Nest 6.6, and sometimes, on the first SearchAsync\<{someclass}\>() call, we get a System.InvalidProgramException: Common Language Runtime detected an invalid program. Here is the stack trace:

System.InvalidProgramException: Common Language Runtime detected an invalid program.  
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.SearchAsync[TResponse](String index, String type, PostData body, SearchRequestParameters requestParameters, CancellationToken ctx)  
at Nest.LowLevelDispatch.SearchDispatchAsync[TResponse](IRequest`1 p, SerializableData`1 body, CancellationToken ct)  
at Nest.ElasticClient.b\_\_562\_0[T,TResult](ISearchRequest p, SerializableData`1 d, CancellationToken c) at Nest.ElasticClient.Nest.IHighLevelToLowLevelDispatcher.DispatchAsync[TRequest,TQueryString,TResponse,TResponseInterface](TRequest request, CancellationToken cancellationToken, Func`3 responseGenerator, Func`4 dispatch)  
at Catalog.ProductCatalogSuggest.Icp.Service.Providers.ElasticsearchSuggestProvider.StoreSuggestAsync(Int32 storeId, String query, Int32 size) in /root/repo/src/Catalog.ProductCatalogSuggest.Icp.Service/Providers/ElasticsearchSuggestProvider.cs:line 89

What's weird is that if we replace this with a standard Search call, we don't get these errors.

Any ideas?

Thanks!

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [February 5, 2020, 11:43pm UTC](https://discuss.elastic.co/t/nest-6-6-getting-invalidprogramexception-sometimes/218058/2 "2020-02-05T23:43:30Z")

</div>

I don't recall seeing this exception before. Can you provide some more details about the environment the application is running in. For example,

- [ASP.NET](http://ASP.NET) Core and version
- .NET Framework/Core runtime and version
- OS Version and/or environment

You say this happens on the first `Search<T>` call. If the AppService/AppDomain/Executable/Process is restarted **without** making any changes to the code, does it consistently happen on the first call?

---

<div class="post-metadata">

**Author:** ![mjessee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mjessee/32/62153_2.png) [@mjessee](https://discuss.elastic.co/u/mjessee)\
**Post date:** [February 5, 2020, 11:55pm UTC](https://discuss.elastic.co/t/nest-6-6-getting-invalidprogramexception-sometimes/218058/3 "2020-02-05T23:55:29Z")

</div>

Russ, I've been able to create a ticket for this: #00487754

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [February 6, 2020, 12:15am UTC](https://discuss.elastic.co/t/nest-6-6-getting-invalidprogramexception-sometimes/218058/4 "2020-02-06T00:15:19Z")

</div>

Thanks @mjessee, will coordinate efforts through the ticket 👍

---

<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:** [March 5, 2020, 12:15am UTC](https://discuss.elastic.co/t/nest-6-6-getting-invalidprogramexception-sometimes/218058/5 "2020-03-05T00:15:21Z")

</div>

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