Note that there are some explanatory texts on larger screens.

plurals
  1. POHelp System.Web.Compilation.BuildManager find a type in a non-referenced assembly
    primarykey
    data
    text
    <p>I'm trying to write a plug-in system where assemblies can be dropped in a folder that ASP.NET has no knowledge about. This plug-in system works fine for ASP.NET MVC based assemblies, but for old-school WebForm assemblies (where the <code>.aspx</code> files <code>Inherits</code> the <code>System.Web.UI.Page</code> derived classes) <code>System.Web.Compilation.BuildManager</code> is responsible for compiling the <code>.aspx</code> file into a dynamic assembly.</p> <p>My problem is that the <code>BuildManager</code> knows nothing about the assemblies within my plug-in folder and it seems to be absolutely nothing I can do to help it. If I do:</p> <pre><code>BuildManager.GetType("PluginAssembly.DefinedType", true, true) </code></pre> <p>it throws. If I first get a reference to the <code>Type</code> and then try:</p> <pre><code>var instance = BuildManager.CreateInstanceFromVirtualPath(path, type); </code></pre> <p>it still throws, even though I've now passed in the specific <code>type</code> it needs to compile the <code>.aspx</code> file. Is there anything I can do to help <code>BuildManager</code> find the types it needs to compile the <code>.aspx</code> file?</p> <p><strong>Update:</strong> I've come one step further, by looking into what <code>BuildManager.GetType()</code> actually does. By specifying the assembly the type is defined in (such as "PluginAssembly.DefinedType, PluginAssembly") and then hooking myself onto the <code>System.AppDomain.CurrentDomain.AssemblyResolve</code> event, I can now find the plug-in assembly and return it so BuildManager can successfully construct the type. This makes the following work with flying colors:</p> <pre><code>BuildManager.GetType("PluginAssembly.DefinedType, PluginAssembly", true, true) </code></pre> <p>However, this still fails:</p> <pre><code>var instance = BuildManager.CreateInstanceFromVirtualPath(path, type); </code></pre> <p>Even though the <code>.aspx</code> file now has the same assembly reference in its <code>Inherits</code> directive:</p> <pre><code>&lt;%@ Page Language="C#" CodeBehind="Index.aspx.cs" Inherits="PluginAssembly.DefinedType, PluginAssembly" %&gt; </code></pre> <p>The error I receive is:</p> <p>"Compiler Error Message: CS0234: The type or namespace name 'DefinedType' does not exist in the namespace 'PluginAssembly' (are you missing an assembly reference?)" with the following source output:</p> <pre><code>Line 205: Line 206: [System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()] Line 207: public class plugins_pluginassembly_dll_index_aspx : global::PluginAssembly.DefinedType, System.Web.SessionState.IRequiresSessionState, System.Web.IHttpHandler { Line 208: Line 209: private static bool @__initialized; </code></pre> <p>It seems like what happens inside <code>BuildManager.CreateInstanceFromVirtualPath()</code> involves a certain <code>System.Web.Util.IWebObjectFactory</code> that it might be responsible for throwing this exception by not finding my assembly. I can implement this interface without any problems, but what does that help if I can't tell the <code>BuildManager</code> about it?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload