Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
pinzart90 committed Apr 24, 2024
1 parent 068adc2 commit 1bcce09
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
16 changes: 10 additions & 6 deletions src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Loader;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
Expand Down Expand Up @@ -49,6 +50,7 @@
using DynamoServices;
using DynamoUtilities;
using ICSharpCode.AvalonEdit;
using J2N.Text;
using Newtonsoft.Json;
using PythonNodeModels;
using ISelectable = Dynamo.Selection.ISelectable;
Expand Down Expand Up @@ -840,14 +842,16 @@ private void CrashGracefully(Exception ex, bool fatal = false)
{
try
{
if (!fatal)
var exceptionAssembly = ex.TargetSite?.Module?.Assembly;
// Do not crash if the exception is coming from a 3d party package;
if (!fatal && exceptionAssembly != null)
{
// Check if the exception might be coming from a loaded package assembly.
var faultyPkg = Model.GetPackageManagerExtension()?.PackageLoader?.LocalPackages?.FirstOrDefault(p =>
{
// Find the first assembly that was loaded fromm the package folder and has the same name as the exception source.
return p.LoadedAssemblies.FirstOrDefault(a => a.WasLoadedFromPackage && (a.Name == ex.Source)) != null;
});
var faultyPkg = Model.GetPackageManagerExtension()?.PackageLoader?.LocalPackages?.FirstOrDefault(p =>
{
return exceptionAssembly.Location.StartsWith(p.RootDirectory, StringComparison.OrdinalIgnoreCase);
}
);
if (faultyPkg != null)
{
var crashDetails = new CrashErrorReportArgs(ex);
Expand Down
17 changes: 2 additions & 15 deletions src/DynamoPackages/Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ public class PackageAssembly
public bool IsNodeLibrary { get; set; }
public Assembly Assembly { get; set; }
public string LocalFilePath {get;set;}
// WasLoadedFromPackage is a flag that represents if the Assembly was actually loaded from the package folder (value = true)
// or if the assembly was already loaded in the appdomain (value = false)
internal bool WasLoadedFromPackage { get; set; }

public string Name
{
Expand Down Expand Up @@ -361,14 +358,7 @@ internal IEnumerable<PackageAssembly> EnumerateAndLoadAssembliesInBinDirectory()
// Use the pkg header to determine which assemblies to load and prevent multiple enumeration
// In earlier packages, this field could be null, which is correctly handled by IsNodeLibrary
var nodeLibraries = Header.node_libraries;

List<string> appDomainAssemblies = null;
var binFiles = new DirectoryInfo(BinaryDirectory).EnumerateFiles("*.dll");
if (binFiles.Any()) {
appDomainAssemblies = AppDomain.CurrentDomain.GetAssemblies().Select(x => x.GetName().Name).ToList();
}

foreach (var assemFile in binFiles)
foreach (var assemFile in new DirectoryInfo(BinaryDirectory).EnumerateFiles("*.dll"))
{
Assembly assem;
//TODO when can we make this false. 3.0?
Expand All @@ -384,16 +374,13 @@ internal IEnumerable<PackageAssembly> EnumerateAndLoadAssembliesInBinDirectory()
var result = PackageLoader.TryLoadFrom(assemFile.FullName, out assem);
if (result)
{
bool alreadyLoaded = appDomainAssemblies?.Contains(assemFile.Name) ?? false;

// IsNodeLibrary may fail, we store the warnings here and then show
IList<ILogMessage> warnings = new List<ILogMessage>();

assemblies.Add(new PackageAssembly()
{
Assembly = assem,
IsNodeLibrary = IsNodeLibrary(nodeLibraries, assem.GetName(), ref warnings),
WasLoadedFromPackage = !alreadyLoaded,
IsNodeLibrary = IsNodeLibrary(nodeLibraries, assem.GetName(), ref warnings)
});

warnings.ToList().ForEach(this.Log);
Expand Down

0 comments on commit 1bcce09

Please sign in to comment.