Skip to content

Exception thrown (TypeLoadException: Access is denied) when using NEST.v7 & Elasticsearch.Net.v7 #4538

@mscerri

Description

@mscerri

NEST/Elasticsearch.Net version: NEST.v7.7.6.0-ci20200401T020447 & Elasticsearch.Net.v7.7.6.0-ci20200401T020447 (from CI)

Elasticsearch version: 7.6.2

Description of the problem including expected versus actual behavior:
When using the NEST.v7 and Elasticseach.Net.v7 packages from CI with updated namespaces and assembly names a TypeLoadException is thrown when trying to load Elasticsearch.Net7.Utf8Json.Resolvers.DynamicCompositeResolver.
To provide some additional context, from my initial investigation it seems that some of the InternalsVisibleTo assembly attributes are not updated correctly when packing the versioned assembly this resulting in a reference the the unversioned assemblies. This might be causing the TypeLoadException: Access is denied. As a reference below are the set assembly attributes in the dlls provided:

NEST.v7.7.6.0-ci20200401T020447

[assembly: InternalsVisibleTo("Elasticsearch.Net.DynamicObjectResolverAllowPrivateFalseExcludeNullTrueNameMutateSnakeCase, PublicKey=*")]
[assembly: InternalsVisibleTo("Elasticsearch.Net.DynamicObjectResolverAllowPrivateFalseExcludeNullFalseNameMutateSnakeCase, PublicKey=*")]
[assembly: InternalsVisibleTo("Elasticsearch.Net.DynamicObjectResolverAllowPrivateFalseExcludeNullFalseNameMutateCamelCase, PublicKey=*")]
[assembly: InternalsVisibleTo("Elasticsearch.Net.DynamicObjectResolverAllowPrivateFalseExcludeNullTrueNameMutateOriginal, PublicKey=*")]
[assembly: InternalsVisibleTo("Elasticsearch.Net.DynamicObjectResolverAllowPrivateFalseExcludeNullTrueNameMutateCamelCase, PublicKey=*")]
[assembly: InternalsVisibleTo("Elasticsearch.Net.DynamicObjectResolverAllowPrivateFalseExcludeNullFalseNameMutateOriginal, PublicKey=*")]
[assembly: InternalsVisibleTo("Elasticsearch.Net.DynamicCompositeResolver, PublicKey=*")]
[assembly: InternalsVisibleTo("Elasticsearch.Net.CustomDynamicObjectResolver, PublicKey=*")]

Elasticsearch.Net.v7.7.6.0-ci20200401T020447

[assembly: InternalsVisibleTo("Elasticsearch.Net.DynamicObjectResolverAllowPrivateFalseExcludeNullTrueNameMutateCamelCase, PublicKey=*")]
[assembly: InternalsVisibleTo("Tests, PublicKey=*")]
[assembly: InternalsVisibleTo("Elasticsearch.Net.DynamicObjectResolverAllowPrivateFalseExcludeNullFalseNameMutateCamelCase, PublicKey=*")]
[assembly: InternalsVisibleTo("Nest7, PublicKey=*")]
[assembly: InternalsVisibleTo("Elasticsearch.Net.DynamicObjectResolverAllowPrivateFalseExcludeNullTrueNameMutateSnakeCase, PublicKey=*")]
[assembly: InternalsVisibleTo("Nest, PublicKey=*")]
[assembly: InternalsVisibleTo("Elasticsearch.Net.DynamicObjectResolverAllowPrivateFalseExcludeNullFalseNameMutateOriginal, PublicKey=*")]
[assembly: InternalsVisibleTo("Elasticsearch.Net.DynamicObjectResolverAllowPrivateFalseExcludeNullTrueNameMutateOriginal, PublicKey=*")]
[assembly: InternalsVisibleTo("Elasticsearch.Net.DynamicCompositeResolver, PublicKey=*")]
[assembly: InternalsVisibleTo("Elasticsearch.Net.CustomDynamicObjectResolver, PublicKey=*")]
[assembly: InternalsVisibleTo("Elasticsearch.Net.DynamicObjectResolverAllowPrivateFalseExcludeNullFalseNameMutateSnakeCase, PublicKey=*")]

I would have expected to see in addition InternalsVisibleTo("Elasticsearch.Net7...")

Steps to reproduce:

  1. Install the above mentioned versions of NEST.v7 and Elasticsearch.Net.v7 (although this occurs on other builds as well)
  2. Initiate a call which requires a Json payload (for example 'elasticClient.Indices.CreateAsync()' with mappings)
  3. Catch exception.

Expected behavior
See above.

Provide DebugInformation (if relevant):

# FailureReason: Unrecoverable/Unexpected BadRequest while attempting PUT on https://mynode/myindex?pretty=true
 - [1] BadRequest: Node: https://mynode/ Exception: TypeLoadException Took: 00:00:00.1179998
# Audit exception in step 1 BadRequest:
System.TypeLoadException: Access is denied: 'Elasticsearch.Net7.Utf8Json.Resolvers.DynamicCompositeResolver'.
   at Elasticsearch.Net7.Utf8Json.JsonFormatterResolverExtensions.GetFormatterWithVerify[T](IJsonFormatterResolver resolver)
   at Elasticsearch.Net7.Utf8Json.JsonSerializer.<SerializeAsync>d__11`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Elasticsearch.Net7.SerializableData`1.<WriteAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Elasticsearch.Net7.HttpWebRequestConnection.<RequestAsync>d__5`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Elasticsearch.Net7.RequestPipeline.<CallElasticsearchAsync>d__57`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Elasticsearch.Net7.Transport`1.<RequestAsync>d__15`1.MoveNext()
# Inner Exception: Access is denied: 'Elasticsearch.Net7.Utf8Json.Resolvers.DynamicCompositeResolver'.
System.TypeLoadException: Access is denied: 'Elasticsearch.Net7.Utf8Json.Resolvers.DynamicCompositeResolver'.
   at Elasticsearch.Net7.Utf8Json.JsonFormatterResolverExtensions.GetFormatterWithVerify[T](IJsonFormatterResolver resolver)
   at Elasticsearch.Net7.Utf8Json.JsonSerializer.<SerializeAsync>d__11`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Elasticsearch.Net7.SerializableData`1.<WriteAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Elasticsearch.Net7.HttpWebRequestConnection.<RequestAsync>d__5`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Elasticsearch.Net7.RequestPipeline.<CallElasticsearchAsync>d__57`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Elasticsearch.Net7.Transport`1.<RequestAsync>d__15`1.MoveNext()
# Exception:
Elasticsearch.Net7.UnexpectedElasticsearchClientException: Access is denied: 'Elasticsearch.Net7.Utf8Json.Resolvers.DynamicCompositeResolver'. ---> System.TypeLoadException: Access is denied: 'Elasticsearch.Net7.Utf8Json.Resolvers.DynamicCompositeResolver'.
   at Elasticsearch.Net7.Utf8Json.JsonFormatterResolverExtensions.GetFormatterWithVerify[T](IJsonFormatterResolver resolver)
   at Elasticsearch.Net7.Utf8Json.JsonSerializer.<SerializeAsync>d__11`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Elasticsearch.Net7.SerializableData`1.<WriteAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Elasticsearch.Net7.HttpWebRequestConnection.<RequestAsync>d__5`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Elasticsearch.Net7.RequestPipeline.<CallElasticsearchAsync>d__57`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Elasticsearch.Net7.Transport`1.<RequestAsync>d__15`1.MoveNext()
   --- End of inner exception stack trace ---
   at Elasticsearch.Net7.Transport`1.<RequestAsync>d__15`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions