Skip to content

Commit

Permalink
Fix related to loading refrences of custom tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed Oct 16, 2023
1 parent a6e2161 commit 1536f53
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions src/netcore/Wexflow.Core/Workflow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -650,38 +650,34 @@ private void Load(string xml)

private void LoadReferences(Assembly assembly)
{
var context = AssemblyLoadContext.GetLoadContext(assembly);
var context = AssemblyLoadContext.Default;
var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().Select(a => a.GetName().Name).ToArray();

if (context != null)
foreach (var reference in assembly.GetReferencedAssemblies())
{
var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().Select(a => a.GetName().Name).ToArray();

foreach (var reference in assembly.GetReferencedAssemblies())
Assembly referenceAssembly = null;
if (loadedAssemblies.All(a => a != reference.Name))
{
if (loadedAssemblies.All(a => a != reference.Name))
var referenceName = $"{reference.Name}.dll";
var referencePath = Path.Combine(AppContext.BaseDirectory, referenceName);

if (File.Exists(referencePath)) // Try to load from AppContext.BaseDirectory
{
referenceAssembly = context.LoadFromAssemblyPath(referencePath);
}
else // Otherwise, try to load from TasksFolder
{
var referenceName = $"{reference.Name}.dll";
var referencePath = Path.Combine(AppContext.BaseDirectory, referenceName);
referencePath = Path.Combine(TasksFolder, referenceName);

Assembly referenceAssembly = null;
if (File.Exists(referencePath))
{
referenceAssembly = context.LoadFromAssemblyPath(referencePath);
}
else
{
referencePath = Path.Combine(TasksFolder, referenceName);

if (File.Exists(referencePath))
{
referenceAssembly = context.LoadFromAssemblyPath(referencePath);
}
}
}

if (referenceAssembly != null) // Recursive load
{
LoadReferences(referenceAssembly);
}
if (referenceAssembly != null) // Recursive load
{
LoadReferences(referenceAssembly);
}
}
}
Expand Down

0 comments on commit 1536f53

Please sign in to comment.