In ASP.NET MVC 5 I used the BuildManager.GetReferencedAssemblies() method to get all the assemblies in the bin folder and load them before the dependency started, so all the dlls were available to be scanned and injected.
Is there an alternative in ASP.NET Core?
I tried this code but it started do give me load errors, like file not found exceptions.
foreach (var compilationLibrary in deps.CompileLibraries)
{
foreach (var resolveReferencePath in compilationLibrary.ResolveReferencePaths())
{
Console.WriteLine($"\t\tReference path: {resolveReferencePath}");
dlls.Add(resolveReferencePath);
}
}
dlls = dlls.Distinct().ToList();
var infolder = dlls.Where(x => x.Contains(Directory.GetCurrentDirectory())).ToList();
foreach (var item in infolder)
{
try
{
Assembly.LoadFile(item);
}
catch (System.IO.FileLoadException loadEx)
{
} // The Assembly has already been loaded.
catch (BadImageFormatException imgEx)
{
} // If a BadImageFormatException exception is thrown, the file is not an assembly.
catch (Exception ex)
{
}
}