zoukankan      html  css  js  c++  java
  • .net项目dll内嵌加载

    1.将dll文件作为嵌入资源添加到项目;

    2.程序入口增加以下代码:

    public partial class App : Application
        {
            private void Application_Startup(object sender, StartupEventArgs e)
            {
                AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            }
    
            private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
            {
                var assName = new AssemblyName(args.Name).FullName;
                if (args.Name == "Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed")
                {
                    var bytes = Music163.Properties.Resources.Newtonsoft_Json;
                    return Assembly.Load(bytes);//加载资源文件中的dll,代替加载失败的程序集
                }
                throw new DllNotFoundException(assName);
            }
        }
  • 相关阅读:
    七夕祭
    Running Median
    电影Cinema
    Best Cow Fences
    Sumdiv
    Tallest Cow
    激光炸弹
    Strange Towers of Hanoi
    Gerald and Giant Chess
    CF24D Broken robot
  • 原文地址:https://www.cnblogs.com/xienb/p/10450117.html
Copyright © 2011-2022 走看看