Type.GetType and ASP.NET 2.0 /App_Code directory

  • Thread starter Thread starter johnrlewis
  • Start date Start date
J

johnrlewis

I need to dynamically create an instance of a class that is in the
/App_Code directory. I do not know the name of the class at
design-time. It is provided to me in the form of a string.

If I use Type.GetType("MyClassName"), I get a null reference because I
did not specify an assembly name. I cannot specify an assembly name
because it is dynamically generated at run-time.

This used to be easy in ASP.NET 1.x because everything was compiled
into a single assembly with a known name. In ASP.NET 2.0 each source
file ends up as a seperate assembly with a random name.

I have seen this question asked many times, but have not seen it
answered. Please help.
 
If I use Type.GetType("MyClassName"), I get a null reference because I
did not specify an assembly name. I cannot specify an assembly name
because it is dynamically generated at run-time.

John:

Use BuildManager.GetType() (System.Web.Compilation). The ASP.NET
BuildManager knows how to look through the dynamic assemblies.
 
Thank you everybody for your replies.

A seperate assembly may be a good idea, but I did not want to stipulate
the users of my library be required to do so.

BuildManager.GetType() worked like a charm. I can specify just the name
of the class with its namespace, leaving out the assembly name, and
BuildManager was able to find the type.

Thanks!!!
 
Back
Top