I'm hooked into the Assembly.Resolve
event and loading assemblies at runtime from embedded resources. This much has been working perfectly for years without a single change to the code.
Recently, I added a new reference to a dll (external.dll
) which has String Resources, and while that assembly resolves without issue, it then attempts to load strings (like NameLang
or PhoneLang
) from its own resources (external.resources
), and is not able to find the resources. The Assembly resolver receives a request for external.resources
and fails to find them.
To be clear, there are no Satellite assemblies, the resources are inside external.dll
, though I understand you could recompile the DLL to put the resources as Satellite Assemblies alongside the DLL, but this isn't compiled that way. Additionally, when I use Telerik JustDecompile, I can see the resource strings (NameLang
and PhoneLang
), so I know they exist within the assembly.
So, I thought maybe I could work around the issue by adding a conditional fork to my Assembly ResolveEventHandler
, to extract the byte array of the Resources from the owning assembly, and load it into the domain but I just get a System.BadImageFormatException
, assumably because the data isn't an assembly, it's an Embedded Resource file, which makes sense.
//^^^get assembly bytes from embedded resource, works
var asm = Assembly.Load(dllBytes);
if (!resourceToFind.Contains(".resources"))
return asm;
else
var resourceNames = asm.GetManifestResourceNames();
var resourceName = resourceNames.FirstOrDefault();
var assemblyData = LoadResourceBytes(asm, resourceName);
return Assembly.Load assemblyData;
//^^^System.BadImageFormatException: Bad IL format. Silly me thinking it would work
So my Primary question is: How do I load the embedded String Resources from an Assembly Resolve event when it's looking for external.resources
?
(and secondarily: Why isn't it able to find it's resources after the assembly has been loaded?)