Skip to content
Draft

Alc dyn #16589

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/DynamoCLI/CommandLineRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected internal static void ImportAssembly(DynamoModel model, string path)
else
{
Console.WriteLine($"attempting to import assembly {path}");
var assembly = System.Reflection.Assembly.LoadFile(path);
var assembly = Dynamo.Utilities.AssemblyHelper.LoadInALCFrom(path);
model.LoadNodeLibrary(assembly, true);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/DynamoCore/Core/NodeModelAssemblyLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ var assembly in
Assembly assembly;
if (!loadedAssembliesByPath.TryGetValue(assemblyPath, out assembly))
{
assembly = Assembly.LoadFrom(assemblyPath);
assembly = Dynamo.Utilities.AssemblyHelper.LoadInALCFrom(assemblyPath);
loadedAssembliesByName[assembly.GetName().Name] = assembly;
loadedAssembliesByPath[assemblyPath] = assembly;
}
Expand Down Expand Up @@ -214,6 +214,7 @@ internal static IEnumerable<Type> GetCustomizationTypesUsingReflection(Assembly
}
try
{
// TODO: ALC issue ? DynamoCoreWpf will probably be loaded only once, in a single ALC?
var customizerType = Type.GetType("Dynamo.Wpf.INodeViewCustomization`1,DynamoCoreWpf");
if (customizerType != null)
{
Expand Down
3 changes: 1 addition & 2 deletions src/DynamoCore/Extensions/ExtensionLoader.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Xml;
using Dynamo.Logging;
using DynamoUtilities;
Expand Down Expand Up @@ -30,7 +29,7 @@ private IExtension Load(ExtensionDefinition extension)
CertificateVerification.CheckAssemblyForValidCertificate(extension.AssemblyPath);
}

var assembly = Assembly.LoadFrom(extension.AssemblyPath);
var assembly = Dynamo.Utilities.AssemblyHelper.LoadInALCFrom(extension.AssemblyPath);
var result = assembly.CreateInstance(extension.TypeName) as IExtension;
ExtensionLoading?.Invoke(result);

Expand Down
2 changes: 1 addition & 1 deletion src/DynamoCore/Library/FunctionDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public string Category
#if DEBUG
var LoadedAssemblyCount = AppDomain.CurrentDomain.GetAssemblies().Length;
#endif
var asm = AppDomain.CurrentDomain.Load(Path.GetFileNameWithoutExtension(Assembly));
var asm = Dynamo.Utilities.AssemblyHelper.LoadInALCFrom(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), Assembly));
#if DEBUG

Debug.Assert(AppDomain.CurrentDomain.GetAssemblies().Length == LoadedAssemblyCount,
Expand Down
4 changes: 2 additions & 2 deletions src/DynamoCore/Library/LibraryCustomization.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
Expand Down Expand Up @@ -89,7 +89,7 @@ public static LibraryCustomization GetForAssembly(string assemblyPath, IPathMana

if (ResolveResourceAssembly(assemblyPath, pathManager, useAdditionalPaths, out resourceAssemblyPath))
{
resAssembly = Assembly.LoadFile(resourceAssemblyPath);
resAssembly = Dynamo.Utilities.AssemblyHelper.LoadInALCFrom(resourceAssemblyPath);
}

// We need 'LibraryCustomization' if either one is not 'null'
Expand Down
5 changes: 2 additions & 3 deletions src/DynamoCore/Library/LibraryServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Metadata.Ecma335;
using System.Xml;
using Dynamo.Configuration;
using Dynamo.Core;
Expand Down Expand Up @@ -106,14 +105,14 @@ private Assembly ResolveAssembly(object sender, ResolveEventArgs args)
{
if (pathManager.ResolveLibraryPath(ref assemblyPath))
{
return Assembly.LoadFrom(assemblyPath);
return Dynamo.Utilities.AssemblyHelper.LoadInALCFrom(assemblyPath);
}

foreach (var packagesDirectory in pathManager.PackagesDirectories)
{
assemblyPath = Path.Combine(packagesDirectory, assemblyName);
if (File.Exists(assemblyPath))
return Assembly.LoadFrom(assemblyPath);
return Dynamo.Utilities.AssemblyHelper.LoadInALCFrom(assemblyPath);
}

return null;
Expand Down
5 changes: 2 additions & 3 deletions src/DynamoCoreWpf/Extensions/ViewExtensionLoader.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Xml;
using Dynamo.Logging;
using DynamoUtilities;
Expand All @@ -20,7 +19,7 @@ internal IViewExtension Load(ViewExtensionDefinition viewExtension)
{
CertificateVerification.CheckAssemblyForValidCertificate(viewExtension.AssemblyPath);
}
var assembly = Assembly.LoadFrom(viewExtension.AssemblyPath);
var assembly = Dynamo.Utilities.AssemblyHelper.LoadInALCFrom(viewExtension.AssemblyPath);
var result = assembly.CreateInstance(viewExtension.TypeName) as IViewExtension;
ExtensionLoading?.Invoke(result);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -268,7 +268,7 @@ public List<Type> LoadAllTypesFromDynamoAssemblies()
{
try
{
var assembly = Assembly.LoadFrom(assemblyPath);
var assembly = Dynamo.Utilities.AssemblyHelper.LoadInALCFrom(assemblyPath);
allLoadedAssemblies[assembly.GetName().Name] = assembly;
List<Type> types = LoadNodesFromAssembly(assembly);
nodeTypes.AddRange(types);
Expand Down Expand Up @@ -392,4 +392,4 @@ private List<Type> LoadNodesFromAssembly(Assembly assembly)

#endregion
}
}
}
4 changes: 2 additions & 2 deletions src/DynamoCoreWpf/TestInfrastructure/DirectoryPathMutator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
Expand All @@ -23,7 +23,7 @@ public override Type GetNodeType()
string assemblyPath = Assembly.GetExecutingAssembly().Location;
string assemblyDir = Path.GetDirectoryName(assemblyPath);
string pathToNodesDll = assemblyDir + "\\nodes\\CoreNodeModels.dll";
Assembly assembly = Assembly.LoadFile(pathToNodesDll);
Assembly assembly = Dynamo.Utilities.AssemblyHelper.LoadInALCFrom(pathToNodesDll);
Type type = assembly.GetType("DSCore.File.Directory");

return type;
Expand Down
6 changes: 3 additions & 3 deletions src/DynamoCoreWpf/TestInfrastructure/DoubleSliderMutator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
Expand All @@ -23,7 +23,7 @@ public override Type GetNodeType()
string assemblyPath = Assembly.GetExecutingAssembly().Location;
string assemblyDir = Path.GetDirectoryName(assemblyPath);
string pathToNodesDll = assemblyDir + "\\nodes\\CoreNodeModels.dll";
Assembly assembly = Assembly.LoadFile(pathToNodesDll);
Assembly assembly = Dynamo.Utilities.AssemblyHelper.LoadInALCFrom(pathToNodesDll);
Type type = assembly.GetType("Dynamo.Nodes.DoubleSlider");

return type;
Expand Down Expand Up @@ -109,7 +109,7 @@ public override bool RunTest(NodeModel node, EngineController engine, StreamWrit
public override int Mutate(NodeModel node)
{
string assemblyPass = Environment.CurrentDirectory + "\\nodes\\CoreNodeModels.dll";
Assembly assembly = Assembly.LoadFile(assemblyPass);
Assembly assembly = Dynamo.Utilities.AssemblyHelper.LoadInALCFrom(assemblyPass);
Type type = assembly.GetType("Dynamo.Nodes.DoubleSlider");

PropertyInfo propInfo = type.GetProperty("Min");
Expand Down
4 changes: 2 additions & 2 deletions src/DynamoCoreWpf/TestInfrastructure/FilePathMutator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
Expand All @@ -23,7 +23,7 @@ public override Type GetNodeType()
string assemblyPath = Assembly.GetExecutingAssembly().Location;
string assemblyDir = Path.GetDirectoryName(assemblyPath);
string pathToNodesDll = assemblyDir + "\\nodes\\CoreNodeModels.dll";
Assembly assembly = Assembly.LoadFile(pathToNodesDll);
Assembly assembly = Dynamo.Utilities.AssemblyHelper.LoadInALCFrom(pathToNodesDll);
Type type = assembly.GetType("DSCore.File.Filename");

return type;
Expand Down
8 changes: 4 additions & 4 deletions src/DynamoCoreWpf/TestInfrastructure/IntegerSliderMutator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
Expand All @@ -23,7 +23,7 @@ public override Type GetNodeType()
string assemblyPath = Assembly.GetExecutingAssembly().Location;
string assemblyDir = Path.GetDirectoryName(assemblyPath);
string pathToNodesDll = assemblyDir + "\\nodes\\CoreNodeModels.dll";
Assembly assembly = Assembly.LoadFile(pathToNodesDll);
Assembly assembly = Dynamo.Utilities.AssemblyHelper.LoadInALCFrom(pathToNodesDll);
Type type = assembly.GetType("Dynamo.Nodes.IntegerSlider");

return type;
Expand Down Expand Up @@ -111,7 +111,7 @@ public override int Mutate(NodeModel node)
string assemblyPath = Assembly.GetExecutingAssembly().Location;
string assemblyDir = Path.GetDirectoryName(assemblyPath);
string pathToNodesDll = assemblyDir + "\\nodes\\CoreNodeModels.dll";
Assembly assembly = Assembly.LoadFile(pathToNodesDll);
Assembly assembly = Dynamo.Utilities.AssemblyHelper.LoadInALCFrom(pathToNodesDll);

Type type = assembly.GetType("Dynamo.Nodes.IntegerSlider");

Expand Down Expand Up @@ -143,4 +143,4 @@ public override int Mutate(NodeModel node)
return returnCode;
}
}
}
}
4 changes: 2 additions & 2 deletions src/DynamoCoreWpf/TestInfrastructure/ListMutator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand All @@ -25,7 +25,7 @@ public override Type GetNodeType()
string assemblyPath = Assembly.GetExecutingAssembly().Location;
string assemblyDir = Path.GetDirectoryName(assemblyPath);
string pathToNodesDll = assemblyDir + "\\nodes\\CoreNodeModels.dll";
Assembly assembly = Assembly.LoadFile(pathToNodesDll);
Assembly assembly = Dynamo.Utilities.AssemblyHelper.LoadInALCFrom(pathToNodesDll);
Type type = assembly.GetType("CoreNodeModels.CreateList");

return type;
Expand Down
4 changes: 2 additions & 2 deletions src/DynamoCoreWpf/TestInfrastructure/NumberRangeMutator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand All @@ -25,7 +25,7 @@ public override Type GetNodeType()
string assemblyPath = Assembly.GetExecutingAssembly().Location;
string assemblyDir = Path.GetDirectoryName(assemblyPath);
string pathToNodesDll = assemblyDir + "\\nodes\\CoreNodeModels.dll";
Assembly assembly = Assembly.LoadFile(pathToNodesDll);
Assembly assembly = Dynamo.Utilities.AssemblyHelper.LoadInALCFrom(pathToNodesDll);
Type type = assembly.GetType("CoreNodeModels.NumberRange");

return type;
Expand Down
4 changes: 2 additions & 2 deletions src/DynamoCoreWpf/TestInfrastructure/NumberSequenceMutator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand All @@ -25,7 +25,7 @@ public override Type GetNodeType()
string assemblyPath = Assembly.GetExecutingAssembly().Location;
string assemblyDir = Path.GetDirectoryName(assemblyPath);
string pathToNodesDll = assemblyDir + "\\nodes\\CoreNodeModels.dll";
Assembly assembly = Assembly.LoadFile(pathToNodesDll);
Assembly assembly = Dynamo.Utilities.AssemblyHelper.LoadInALCFrom(pathToNodesDll);
Type type = assembly.GetType("CoreNodeModels.NumberSeq");

return type;
Expand Down
2 changes: 1 addition & 1 deletion src/DynamoCoreWpf/Utilities/CrashReportTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private static string FindCERToolInInstallLocations()
if (!File.Exists(assemblyPath))
throw new FileNotFoundException(assemblyPath);

var assembly = Assembly.LoadFrom(assemblyPath);
var assembly = Dynamo.Utilities.AssemblyHelper.LoadInALCFrom(assemblyPath);
type = assembly.GetType("DynamoInstallDetective.Utilities");
}

Expand Down
3 changes: 2 additions & 1 deletion src/DynamoPackages/PackageLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Loader;
using Dynamo.Core;
using Dynamo.Exceptions;
using Dynamo.Extensions;
Expand Down Expand Up @@ -744,7 +745,7 @@ internal static bool TryLoadFrom(string filename, out Assembly assem)
{
try
{
assem = Assembly.LoadFrom(filename);
assem = AssemblyHelper.LoadInALCFrom(filename);
return true;
}
catch (FileLoadException e)
Expand Down
5 changes: 3 additions & 2 deletions src/DynamoSandbox/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Dynamo.Utilities;
using Dynamo.Wpf.Utilities;
using System;
using System.Diagnostics;
Expand Down Expand Up @@ -45,13 +46,13 @@ public static Assembly ResolveAssembly(object sender, ResolveEventArgs args)
{
string assemblyPath = Path.Combine(DynamoCorePath, assemblyName);
if (File.Exists(assemblyPath))
return Assembly.LoadFrom(assemblyPath);
return AssemblyHelper.LoadInALCFrom(assemblyPath);

var assemblyLocation = Assembly.GetExecutingAssembly().Location;
var assemblyDirectory = Path.GetDirectoryName(assemblyLocation);

assemblyPath = Path.Combine(assemblyDirectory, assemblyName);
return (File.Exists(assemblyPath) ? Assembly.LoadFrom(assemblyPath) : null);
return (File.Exists(assemblyPath) ? AssemblyHelper.LoadInALCFrom(assemblyPath) : null);
}
catch (Exception ex)
{
Expand Down
13 changes: 10 additions & 3 deletions src/DynamoUtilities/AssemblyHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.Loader;

namespace Dynamo.Utilities
{
Expand Down Expand Up @@ -50,7 +51,7 @@ public Assembly ResolveAssembly(object sender, ResolveEventArgs args)
Console.WriteLine("loading from " + assemblyPath);

}
return Assembly.LoadFrom(assemblyPath);
return LoadInALCFrom(assemblyPath);
}

// Then check all additional resolution paths
Expand All @@ -68,7 +69,7 @@ public Assembly ResolveAssembly(object sender, ResolveEventArgs args)
{
Console.WriteLine("loading from " + assemblyPath);
}
return Assembly.LoadFrom(assemblyPath);
return LoadInALCFrom(assemblyPath);
}
}

Expand All @@ -89,5 +90,11 @@ public static Version GetDynamoVersion(bool includeRevisionNumber = true)
? version
: new Version(version.Major, version.Minor, version.Build, 0);
}

internal static Assembly LoadInALCFrom(string assemblyPath, AssemblyLoadContext alc = null)
{
alc ??= AssemblyLoadContext.GetLoadContext(Assembly.GetExecutingAssembly());
return alc.LoadFromAssemblyPath(assemblyPath);
}
}
}
2 changes: 1 addition & 1 deletion src/DynamoUtilities/Md2Html.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.IO;
using System.Text;
using System.Threading;
using DynamoUtilities.Properties;
using DynamoUtility.Properties;
using Newtonsoft.Json.Linq;

namespace Dynamo.Utilities
Expand Down
4 changes: 4 additions & 0 deletions src/DynamoUtilities/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@
[assembly: InternalsVisibleTo("Notifications")]
[assembly: InternalsVisibleTo("SystemTestServices")]
[assembly: InternalsVisibleTo("NodeAutoCompleteViewExtension")]
[assembly: InternalsVisibleTo("DynamoSandbox")]
[assembly: InternalsVisibleTo("DynamoWPFCLI")]
[assembly: InternalsVisibleTo("DynamoPythonTests")]
[assembly: InternalsVisibleTo("NodeDocumentationMarkdownGeneratorTests")]
2 changes: 1 addition & 1 deletion src/DynamoUtilities/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/DynamoWPFCLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#endif
using System.Threading;
using Dynamo.Applications;
using Dynamo.Logging;
using Dynamo.Models;
using Dynamo.Utilities;
using Dynamo.ViewModels;
using Dynamo.Wpf.ViewModels.Watch3D;
using static System.Windows.Threading.Dispatcher;
Expand Down Expand Up @@ -156,7 +156,7 @@ private static void ImportAssembly(DynamoModel model, string path)
else
{
Console.WriteLine($"attempting to import assembly {path}");
var assembly = System.Reflection.Assembly.LoadFile(path);
var assembly = AssemblyHelper.LoadInALCFrom(path);
model.LoadNodeLibrary(assembly, true);
}
}
Expand Down
Loading
Loading