I'm looking to embed and load dll files into my class library so that it can be contained in one dll.
I have a Class Library called Wraper.
I'm using a Console application called ConsoleApp to run the Wraper Class Library.
class Program
{
static void Main(string[] args)
{
Wallet X = new Wallet();
X.SendPayment("1", "Driver={ODBC Driver 17 for SQL Server};Server=.;Database=Home;Trusted_Connection=yes;");
}
}
I have my dll files in the Wraper project in a folder called EmbeddedAssemblies
I'm wanting to load these files in my project. Here is the code that I have in my Wraper Class Library:
public void SendPayment(string DCode, string ConnectionString)
{
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
...
Console.WriteLine("A break point WILL stop here.");
...
}
// This method does not seem to run. Why????
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
...
Console.WriteLine("A break point WILL NOT stop here.");
...
string baseResourceName = Assembly.GetExecutingAssembly().GetName().Name + "." + new AssemblyName(args.Name).Name;
byte[] assemblyOdbc = null;
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Wraper.EmbeddedAssemblies.System.Data.Odbc.dll"))
{
assemblyOdbc = new Byte[stream.Length];
stream.Read(assemblyOdbc, 0, assemblyOdbc.Length);
}
byte[] assemblyNewton = null;
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Wraper.EmbeddedAssemblies.Newtonsoft.Json.dll"))
{
assemblyNewton = new Byte[stream.Length];
stream.Read(assemblyNewton, 0, assemblyNewton.Length);
}
Console.WriteLine("loaded");
return Assembly.Load(assemblyOdbc, assemblyNewton);
}
I'm not sure why this is not working it builds with no errors however when I put a break point just inside the CurrentDomain_AssemblyResolve method it does not even go to the break point, thus the assembly(s) do not load.
What am I doing wrong?