Skip to content

Commit

Permalink
Added error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
TBN-MapleWheels committed Sep 7, 2023
1 parent d3acdb2 commit bcf734e
Showing 1 changed file with 47 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -564,25 +564,34 @@ internal AssemblyManager()
.SelectMany(a => a.GetSafeTypes())
.ToImmutableDictionary(t => t.FullName ?? t.Name, t => t);
}
catch (ArgumentException _)
catch(ArgumentException _)
{
// some types must've had duplicate type names, build the list while filtering
Dictionary<string, Type> types = new();
foreach (var type in AssemblyLoadContext.Default.Assemblies.SelectMany(a => a.GetSafeTypes()))
try
{
if (!types.ContainsKey(type.FullName ?? type.Name))
types.Add(type.FullName ?? type.Name, type);
}
// some types must've had duplicate type names, build the list while filtering
Dictionary<string, Type> types = new();
foreach (var type in AssemblyLoadContext.Default.Assemblies.SelectMany(a => a.GetSafeTypes()))
{
try
{
types.TryAdd(type.FullName ?? type.Name, type);
}
catch
{
// ignore, null key exception
}
}

_defaultContextTypes = types.ToImmutableDictionary();
}
catch(Exception e)
{
ModUtils.Logging.PrintError($"{nameof(AssemblyManager)}: Unable to create list of default assembly types! Default AssemblyLoadContext types searching not available.");
_defaultContextTypes = types.ToImmutableDictionary();
}
catch (Exception e)
{
ModUtils.Logging.PrintError($"{nameof(AssemblyManager)}: Unable to create list of default assembly types! Default AssemblyLoadContext types searching not available.");
#if DEBUG
ModUtils.Logging.PrintError($"{nameof(AssemblyManager)}: Exception Details :{e.Message} | {e.InnerException}");
ModUtils.Logging.PrintError($"{nameof(AssemblyManager)}: Exception Details :{e.Message} | {e.InnerException}");
#endif
_defaultContextTypes = ImmutableDictionary<string, Type>.Empty;
_defaultContextTypes = ImmutableDictionary<string, Type>.Empty;
}
}
}

Expand Down Expand Up @@ -622,9 +631,30 @@ internal LoadedACL(Guid id, AssemblyManager manager)
internal void RebuildTypesList()
{
ClearTypesList();
_assembliesTypes = this.Acl.Assemblies
.SelectMany(a => a.GetSafeTypes())
.ToImmutableDictionary(t => t.FullName ?? t.Name, t => t);
try
{
_assembliesTypes = this.Acl.Assemblies
.SelectMany(a => a.GetSafeTypes())
.ToImmutableDictionary(t => t.FullName ?? t.Name, t => t);
}
catch(ArgumentException _)
{
// some types must've had duplicate type names, build the list while filtering
Dictionary<string, Type> types = new();
foreach (var type in this.Acl.Assemblies.SelectMany(a => a.GetSafeTypes()))
{
try
{
types.TryAdd(type.FullName ?? type.Name, type);
}
catch
{
// ignore, null key exception
}
}

_assembliesTypes = types.ToImmutableDictionary();
}
}

internal void ClearTypesList() => _assembliesTypes.Clear();
Expand Down

0 comments on commit bcf734e

Please sign in to comment.