简体   繁体   中英

c# Embed Resource dll

I have a function that need a dll Resource

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

it requires : SQLite.Interop.dll

so instead of putting that dll in the same Enviroment folder i use it as an embedded resource :

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

            }
        }

But it still throw an exception :

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

EDIT : Solved by adding the whole new class to the project instead of refering to it as a dll reference

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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