I have a DLL >> System.Data.SQLite.dll
To use it in a normal way > just add it as reference and
using System.Data.SQLite;
then, I can use all the functions inside this DLL.
But, I want to merge my app.exe and this DLL into one single file. I have tried using ILmerge, but fail. As I know, ILmerge cannot merge unmanage DLL.
So, I tried another method > make the DLL as embbed resource. I am able to load it as an assembly with the below code:
Stream stm = Assembly.GetExecutingAssembly().GetManifestResourceStream("MyApp.System.Data.SQLite.dll");
byte[] ba = null;
byte[] buffer = new byte[16 * 1024];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = stm.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
ba = ms.ToArray();
}
Assembly sSQLiteDLL = Assembly.Load(ba);
but, how am I going to use the functions in SQLiteDLL?
I also tried add the DLL as resource in properties and load it like this:
public Form1()
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
InitializeComponent();
}
System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
AppDomain domain = (AppDomain)sender;
if (args.Name.Contains("System_Data_SQLite"))
{
return domain.Load(MyApp.Properties.Resources.System_Data_SQLite);
}
return null;
}
The above explained what I've got so far and I don't know what to do next to use the DLL? I still can't use the functions inside the DLL.
For example, when I type this:
SQLiteCommand cmd = new SQLiteCommand();
The Visual Studio says:
Error 21 The type or namespace name 'SQLiteCommand' could not be found (are you missing a using directive or an assembly reference?)
Can you share your insight? Thanks.