AssemblyResolve event is not firing during compilation of a dynamic assembly for an aspx page.

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-05-16T00:33:56Z Indexed on 2010/05/16 0:40 UTC
Read the original article Hit count: 270

Filed under:
|
|
|

This one is really pissing me off. Here goes:

My goal is to load assemblies at run-time that contain embedded aspx,ascx etc. What I would also like is to not lock the assembly file on disk so I can update it at run-time without having to restart the application (I know this will leave the previous version(s) loaded).

To that end I have written a virtual path provider that does the trick. I have subscribed to the CurrentDomain.AssemblyResolve event so as to redirect the framework to my assemblies.

The problem is that the when the framework tries to compile the dynamic assembly for the aspx page I get the following:

Compiler Error Message: CS0400: The type or namespace name 'Pages' could not be found in the global namespace (are you missing an assembly reference?)

Source Error: public class app_resource_pages__version_1_0_0_0__culture_neutral__publickeytoken_null_default_aspx : global::Pages._Default, System.Web.SessionState.IRequiresSessionState, System.Web.IHttpHandle

I noticed that if I load the assembly with Assembly.Load(AssemblyName) or Assembly.LoadFrom(filename) I dont get the above error. If I load it with Assembly.Load(byte[]) (so as to not lock it), the exception is thrown but my AssemblyResolve handler, when called is returning the assembly correctly (it is called once).

So I am guessing that it is called once when the framework parses the asp markup but not when it tries to create the dynamic assembly for the aspx page.

© Stack Overflow or respective owner

Related posts about c#

Related posts about reflection