AssemblyLoadContext.Unload不会卸载Wpf库。
创始人
2024-09-20 14:30:28
0

在.NET Core中,使用AssemblyLoadContext.Unload方法无法卸载WPF库,因为WPF库在加载时会注册一些全局的资源和事件处理器,无法完全卸载。但是,可以通过使用AppDomain来加载和卸载WPF库。

以下是一个示例代码,演示如何使用AppDomain来加载和卸载WPF库:

using System;
using System.Reflection;

class Program
{
    static void Main(string[] args)
    {
        // 创建一个新的AppDomain
        AppDomain appDomain = AppDomain.CreateDomain("MyAppDomain");

        try
        {
            // 在新的AppDomain中加载WPF库
            appDomain.Load("PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");

            // 使用反射创建WPF应用程序实例
            Type wpfAppType = appDomain.GetType("System.Windows.Application");
            object wpfApp = Activator.CreateInstance(wpfAppType);

            // 调用WPF应用程序的Run方法
            MethodInfo runMethod = wpfAppType.GetMethod("Run");
            runMethod.Invoke(wpfApp, null);
        }
        finally
        {
            // 卸载AppDomain
            AppDomain.Unload(appDomain);
        }
    }
}

请注意,这个示例只是演示了如何在新的AppDomain中加载和卸载WPF库。实际开发中,您可能需要根据具体需求做一些调整。

相关内容

热门资讯

透视肯定!wepoker私人局... 透视肯定!wepoker私人局外卦,wepoker免费脚本弱密码(透视)新版2025教程(有挂攻略)...
透视神器!WePOker有没有... 透视神器!WePOker有没有透视方法,we-poker有人玩吗(透视)详细教程(有挂解说);1、完...
透视游戏!wepoker有没有... 透视游戏!wepoker有没有挂,wepoker私人局外卦(透视)技巧教程(有挂揭秘)1、全新机制【...
透视工具!WePoKer辅助器... 透视工具!WePoKer辅助器,wepoker脚本下载(透视)科技教程(有挂细节);在进入wepok...
透视好友房!we-poker靠... 透视好友房!we-poker靠谱吗,we-poker正规吗(透视)实用技巧(有挂辅助)we-poke...
透视中牌率!wejoker辅助... 透视中牌率!wejoker辅助器怎么卖,wepoker透视苹果系统(透视)存在挂教程(有挂细节);暗...
透视ai!wepoker高级辅... 透视ai!wepoker高级辅助,wepoker轻量版透视系统(透视)透视教程(有挂黑科技)透视ai...
透视透视挂!wepoker辅助... 透视透视挂!wepoker辅助分析器,如何下载wepoker安装包(透视)玩家教程(有挂解密)所有人...
透视科技!wepoker透视挂... 透视科技!wepoker透视挂底牌,wepoker插件下载(透视)必赢方法(有挂脚本)在进入wepo...
透视辅助!wepoker能不能... 透视辅助!wepoker能不能透视,wepoker的辅助器(透视)力荐教程(有挂辅助)1、透视辅助!...