Check "Does Not Support Unloading" tag to not use AssemblyLoadContext

This commit is contained in:
Stone_Red
2025-12-20 16:08:30 +01:00
parent 780b506103
commit ac7826898a
2 changed files with 17 additions and 3 deletions
@@ -1,6 +1,8 @@
using Modio.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
namespace DesktopMagic.Plugins;
@@ -27,6 +29,8 @@ public class PluginMetadata
public string? Version { get; set; }
public List<string> Tags { get; set; } = [];
public PluginMetadata(Mod mod)
{
Name = mod.Name ?? mod.Id.ToString();
@@ -39,6 +43,7 @@ public class PluginMetadata
Description = mod.DescriptionPlaintext;
Summary = mod.Summary;
Version = mod.Modfile?.Version;
Tags = mod.Tags.Select(t => t.Name).Where(t => t is not null).ToList()!;
}
public PluginMetadata(string name, uint id)
+12 -3
View File
@@ -216,10 +216,19 @@ public partial class PluginWindow : Window
object? instance = pluginClassInstance;
if (instance is null)
{
byte[] assemblyData = File.ReadAllBytes($"{PluginFolderPath}\\main.dll");
using MemoryStream assemblyStream = new(assemblyData);
Assembly dll;
Assembly dll = assemblyLoadContext.LoadFromStream(assemblyStream);
if (PluginMetadata.Tags.Contains("Does Not Support Unloading"))
{
dll = Assembly.LoadFrom($"{PluginFolderPath}\\main.dll");
}
else
{
byte[] assemblyData = File.ReadAllBytes($"{PluginFolderPath}\\main.dll");
using MemoryStream assemblyStream = new(assemblyData);
dll = assemblyLoadContext.LoadFromStream(assemblyStream);
}
Type? instanceType = Array.Find(dll.GetTypes(), type => type.GetTypeInfo().BaseType == typeof(Plugin));