Good afternoon,
I've succesfully embedded a C# class dll file into my app, I can print out it being there via:
Console.WriteLine(Assembly.GetExecutingAssembly()
.GetManifestResourceInfo("TestReferenceLib.dll").ResourceLocation);
But, even if I load it as so:
public static void Main(string[] args)
{
Console.WriteLine(Assembly.GetExecutingAssembly().GetManifestResourceInfo("TestReferenceLib.dll").ResourceLocation);
//This doesn't even fire
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler((o, e) =>
{
Console.WriteLine("Resolving?");
var memory = new MemoryStream();
Assembly.GetExecutingAssembly().GetManifestResourceStream(e.Name + ".dll").CopyTo(memory);
if(memory.Length > 0)
return Assembly.Load(memory.ToArray());
return null;
});
Console.WriteLine("Test assembly compiled and ran succesfully!");
//Pops errors
TestReferenceLib.TestReferenceLibrary.PrintOut();
}
The line marked with comment 'Pops errors' says:
FileNotFoundException: Could not load file or assembly 'TestReferenceLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
I know that I could walk around it by taking the assembly returned by Assembly.Load(); and run GetType(), GetMethod() and Invoke() to make it work - or use tools like ILMerge or similar to make it work - but without going too much in depth, it's crucial for me not to use any external tools.
The reference via 'using TestReferenceLib' HAS to work.
Thank you in advance for any tips.
Update
With this little piece of code I manage to get it listed in loaded assemblies, but executing still doesn't work:
var memory = new MemoryStream();
Assembly.GetExecutingAssembly().GetManifestResourceStream("TestReferenceLib.dll").CopyTo(memory);
var assembly = AppDomain.CurrentDomain.Load(memory.ToArray());
foreach (var a in Assembly.GetExecutingAssembly().GetReferencedAssemblies())
{
Console.WriteLine(a.FullName);
}
foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
{
Console.WriteLine(a.FullName);
}