Autofac dynamic assembly binding not working
- Dominant language
- PowerShell
- Stars
- 1.1k
- Forks
- 215
- Avg merge
- 4h 2m
- Merged PRs (30d)
- 1
Description
Not sure how assembly references get resolved in Azure Function but the following code works fine in a console app(I have tried with both .net core console and .net 4.6.1 console). If I try to use the same code in a function app, I would get the error messages I have mentioned in my code comments. I am using latest version (15.10.2046.0) of Functions and Web Job Tools.
Note: I have manually copied myplugin.dll into my function app's bin folder. Same thing I have done with my console app where the same code works.
```
var assemblyRoot = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var pluginPath = Directory.GetFiles(assemblyRoot, $"myplugin.dll").FirstOrDefault();
var pluginAssembly = Assembly.LoadFile(pluginPath);
var builder = new ContainerBuilder(); // I am using Autofac
builder.RegisterAssemblyTypes(pluginAssembly).AsImplementedInterfaces().SingleInstance();
var container = builder.Build();
// Here I am getting errors like "Unable to find assembly ''. Are you missing a private assembly file?" for various referenced assemblies like automapper, MongoDB.Bson etc.
var plugIn = container.Resolve();
// Here I am getting "'IPlugIn' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.'"
```
Any help or insight would be appreciated. Thank you.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.