Type.GetType() ASP.NET Beta 2

G

Guest

Hi

I have a class in the App_Code location of my web project.

example:
namespace Company.AppName.Objects {
public class ObjectA {
public ObjectA(){
}

public void DoSomething() {
}
}
}

In a web page I want to dynamically get the type of this class like so:

Type t = Type.GetType("Company.AppName.Objects.ObjectA");

However this code will return a null null object, due to the compilation
model of ASP.NET 2, it basically can't find the dll to load the type.
ASP.NET 1.x didn't have this problem because the code-behind was represented
in a single dll.

Apart from say putting ObjectA into it's own project thus dll, does anyone
know of a way around this?

Craig
 
G

Guest

Hi Brock

Do you have any suggestions on how I can make this functionality work for me
under ASP.NET v2?

Craig
 
G

Guest

Hi Brock

Yeah typeof would certainly do the trick, the problem is my page has a
drop-down control with ListItems as:
<option value="Company.Project.Objects.ObjectA">ObjectA</option>

From the SelectedValue property I wish to create the type, as I mentioned,
ASP.NET 2 compilation model means that ObjectA won't be compiled until
invoked (assuming this is correct).

After some digging around, I found the aspnet_compiler.exe. This allows for
pre-compiled code of the App_code folder. So now I can use
Type t = Type.GetType("Company.Project.Objects.ObjectA");

Which returns the correct type. I'm yet to find holes in this approach
which is a good sign.

Craig
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top