views:

652

answers:

5

I have a class Customer in app_code folder in asp.net web site, how can I create an instance using reflection, for example using Activator.CreateInstance(assemblyName, typeName)? Because the app_code is dynamically compiled, I don't know the assembly in design time?

Thanks Fred

The question is should be how get a full name of type in design time, I want to put it in web.config. I have ConfigSection type, it is in app_code folder, I need to declare it in configSection. Thanks

+2  A: 

I think you can use Assembly.GetExecutingAssembly() to get a reference to the current assembly.

BrianLy
This worked for me, thanks!
Gus
A: 

You can also use GetType().Assembly if you know that it will be the same assembly as your currently executing code.

Matt Briggs
A: 

The question is should be how get a full name of type in design time, I want to put it in web.config. I have ConfigSection type, it is in app_code folder, I need to declare it in configSection. Thanks

+1  A: 

You should be able to use "App_Code" or "__Code" as the assembly name in the web.config

Matt Briggs
A: 

I have solved a similar problem in this way:

Type[] appCodeTypes = System.Reflection.Assembly.Load("App_Code").GetTypes();
Flatlineato