Resolve dependency when an assembly is loaded using Assembly.Load(byte[])
<p>I use Assembly.Load(byte[]) to load an assembly. This loaded assembly internally uses codeDomProvider.CompileAssemblyFromSource() to compile code which is failing with error 'The type or namespace name '&lt;ClassName&gt;' could not be found (are you missing a using directive or an assembly reference?)'.</p>

<p>AppDomain.AssemblyResolve event is not fired for the references present in the code to compile.</p>

<p>FYI: I am trying to load assembly which uses <a href="http://www.filehelpers.net/" rel="nofollow">FileHelpers.dll</a> and it calls on ClassBuilder.ClassFromString function. Assembly load fails with RunTimeCompilationException.</p>

<p>How should I resolve such dependencies?</p>

<p>UPDATE:</p>

<p>Here is code I am using</p>

<pre><code>ctor()
{
    AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve;
}

private Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs args)
{
    AssemblyName assemblyName = new AssemblyName(args.Name);
    return LoadAssembly(assemblyName);
}

public Assembly GetAssembly(string assemblyFullName)
{
    AssemblyName assemblyName = new AssemblyName(assemblyFullName);

    Assembly assembly = LoadAssembly(assemblyName) ?? Assembly.Load(assemblyName);
}

private Assembly LoadAssembly(AssemblyName assemblyName)
{
    byte[] assemblyBytes = GetAssemblyBytes(); // Get assembly bytes from external source
    return Assembly.Load(assemblyBytes);
}
</code></pre>

<p>Thanks</p>

<p>Yash</p>