I am migrating my web app from ASP.NET Core RC1 to RC2. I'm trying to load my referenced class libraries.
This code snippet doesn't work with RC2 any more:
public class Startup
{
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
// libraryManager is null ....
ILibraryManager libraryManager = app.GetService<ILibraryManager>();
List<Assembly> result = new List<Assembly>();
IEnumerable<Library> libraries = libraryManager.GetLibraries();
IEnumerable<AssemblyName> assemblyNames = libraries.SelectMany(e => e.Assemblies).Distinct();
assemblyNames = Enumerable.Where(assemblyNames, e => e.Name.StartsWith("projectNamespace"));
foreach (AssemblyName assemblyName in assemblyNames)
{
Assembly assembly = Assembly.Load(assemblyName);
.
.
.
}
}
}
I found a solution. I'm using now DependencyContext
instead of ILibraryManager
var loadableAssemblies = new List<Assembly>();
var deps = DependencyContext.Default;
foreach (var compilationLibrary in deps.CompileLibraries)
{
if (compilationLibrary.Name.Contains(projectNamespace))
{
var assembly = Assembly.Load(new AssemblyName(compilationLibrary.Name));
loadableAssemblies.Add(assembly);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With