繁体   English   中英

c#嵌入资源DLL

[英]c# Embed Resource dll

我有一个需要dll资源的函数

    using (SQLiteConnection c = new SQLiteConnection("Data Source=logindata;Version=3;"))
    {
    }

它需要: SQLite.Interop.dll

所以不要将该dll放在同一个Enviroment文件夹中,而是将其用作嵌入式资源:

   [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            Application.Run(new Form1());
        }

        private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("EmbedAssembly.SQLite.Interop.dll"))
            {
                byte[] Data = new byte[stream.Length];
                stream.Read(Data, 0, Data.Length);
                return Assembly.Load(Data);

            }
        }

但它仍然抛出异常:

Unable to load DLL 'SQLite.Interop.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

编辑 :解决方法是将全新类添加到项目中,而不是将其作为dll引用引用

通过将全新的Sqlite类添加到我的项目而不是将其添加到我的项目作为参考来解决。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM