码迷,mamicode.com
首页 > Web开发 > 详细

.net项目dll内嵌加载

时间:2019-02-28 14:56:12      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:resolve   cat   star   sof   code   resource   current   sem   assembly   

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);
        }
    }

 

.net项目dll内嵌加载

标签:resolve   cat   star   sof   code   resource   current   sem   assembly   

原文地址:https://www.cnblogs.com/xienb/p/10450117.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!