My application loads the assemblies it needs through an event AppDomain.CurrentDomain.AssemblyResolve
. Assemblies are the resources of the executing assembly.
private static Assembly OnResolveAssembly(object sender, ResolveEventArgs args)
{
var executingAssembly = Assembly.GetExecutingAssembly();
var assemblyName = new AssemblyName(args.Name);
var resPath = assemblyName.Name + ".dll";
using (var stream = executingAssembly.GetManifestResourceStream(resPath))
{
if (stream != null)
{
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
return Assembly.Load(buffer);
}
}
return null;
}
This works fine overall, but the downloadable assembly contains default styles for certain controls that will not apply. BUT, if I do not load the assembly through Assembly.Load, but save it to a file and load through Assembly.LoadFrom
, everything works fine.
What is the difference between the two? Why doesn't it work when loading an assembly directly from memory - or why does it work when it first saves it to disk and then loads it with Assembly.LoadFrom
?
I am very confused and I want to load assemblies directly from memory without saving them in the first place.
source
share