Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Core loads assemblies using an API that loads them into the wrong AssemblyLoadContext #5662

Closed
SeanFeldman opened this issue Jun 2, 2020 · 3 comments · Fixed by #5913

Comments

@SeanFeldman
Copy link
Contributor

SeanFeldman commented Jun 2, 2020

Assemblies are loaded by the AssemblyScanner using Assembly.LoadFrom(assemblyPath) API. When running within Azure Functions in .NET Core, assemblies scanned and loaded appear to have a different AssemblyLoadContext.

image

vs

image

That's causing types from the loaded assemblies to fail reference equality check. In turn, that causes message handlers identification to fail and messages not being associated with message handlers. This can be resolved by loading assemblies using a shared AssemblyLoadContext when running in .NET Core. 

#if NETCOREAPP2_1
  var context = AssemblyLoadContext.GetLoadContext(Assembly.GetExecutingAssembly());
  assembly = context.LoadFromAssemblyPath(assemblyPath);
#else
  assembly = Assembly.LoadFrom(assemblyPath);
#endif

A spike PR has been created in place: #5652

@timbussmann

This comment has been minimized.

@SeanFeldman

This comment has been minimized.

@SeanFeldman SeanFeldman transferred this issue from Particular/NServiceBus.AzureFunctions.InProcess.ServiceBus Jun 8, 2020
@SeanFeldman SeanFeldman changed the title Azure Functions and Assembly Scanning issue The Core loads assemblies using an API that loads them into the wrong AssemblyLoadContext Jun 8, 2020
@Particular Particular deleted a comment from SeanFeldman Dec 7, 2020
@Particular Particular deleted a comment from SeanFeldman Dec 7, 2020
@Particular Particular deleted a comment from SeanFeldman Dec 7, 2020
@adamralph adamralph added the Bug label Jan 21, 2021
@bording
Copy link
Member

bording commented Feb 19, 2021

Fixed by #5913

@bording bording closed this as completed Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants