Loading assemblies from database in an ASP.NET application

  • Thread starter Thread starter Tor Bådshaug
  • Start date Start date
T

Tor Bådshaug

BlankHi,
I am having trouble loading assemblies from the database in my ASP.NET app.

I have a default.aspx in my app that is served from a database via a custom virtual path provider. This works fine, until this
default.aspx uses code in a dependent assembly (say CustomAssembly). Then ASP.NET cannot find the class "CustomAssembly.MyClass" and files
to compile the default.aspx.

I've tried to do a

AppDomain.CurrentDomain.Load(byte[] rawAssembly)

up front (prior to default.aspx compilation) to help ASP.NET to find this class, but the ASP.NET runtime looks to ignore it. However, I can successfully do

AppDomain.CurrentDomain.CreateInstance("CustomAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "CustomAssembly.MyClass");

Also, I can verify that the "CustomAssembly" is actually loaded by looking at the value of AppDomain.CurrentDomain.GetAssemblies().
The custom assembly i loaded from database is included there, get its codebase set to something like file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/Temporary%20ASP.NET%20Files/root/300b5c74/97825cbb/assembly/dl3/95cc4ab5/aa815946_b9bac801/AppWeb.DLL

Why does ASP.NET ignore the existence of classes that are actually loaded into the runtime and are accessible through reflection?
Any suggestions on the next steps to achieve the dynamical loading I am seeking?
(I need to create a sort of host application to which modules can be plugged/deployed in at runtime)

-Tor
 
to compile a page, the compiler needs read access to dll also so it can
resolve symbols and method signatures. also the asp.net compiler has limited
path search capabilities. in the case of non-gac assemblies, they must be in
the bin folder.

you could have the pages load the assemblies at runtime, and a set of
interfaces may make this practical. i've done this before - loading the
assembly from the database, and calling a known iteface (and sometimes used
reflection).

you could also do what asp.net does. create a temp folder, copy the page
source and database dlls to the temp folder. compile the page (can use the
aspnet_compiler), then load the compiled page assembly from the temp folder.
(be sure to load the database dll once). this is probably the approach you
want to do if the pages can not be precompiled.

-- bruce (sqlwork.com)


-- bruce (sqlwork.com)
 
Back
Top