I'm trying to write a plugin system for a website whereby a user can drop a class in the App_Code directory and then pass the class name on the query string of the aspx file and the ASPX will create an instance of this class.
I've been pratting about with various things but this is my first attempt/hack at reflection.
What i have so far in my Aspx codebeheind is
Expand|Select|Wrap|Line Numbers
- namespace MyNS{
- public partial class _Default :System.Web.UI.Page {
- string _class = Request.QueryString["class"];
-
object instance = Activator.CreateInstance(this.GetType().AssemblyQualifiedName,
}this.GetType().Assembly+"." + _class);
- }
Expand|Select|Wrap|Line Numbers
- namespace MyNS {
- public class TestClass {
- public TestClass() {
- //
- // TODO: Add constructor logic here
- //
- }
- public string Get() {
- return this.ToString();
- }
- }
- }
I thought by wrapping both bits of code in the same namespace i would be able to make use of
this.GetType().AssemblyQualifiedName
from the aspx but i get this error
Expand|Select|Wrap|Line Numbers
- Could not load file or assembly 'ASP.Default_aspx\, App_Web_jbgiblwi\, Version\=0.0.0.0\, Culture\=neutral\, PublicKeyToken\=null' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
Thanks for any help.
Greg