1

Help, here is the idea:

External.dll
IMyClass NewCreated = (IMyClass)Activator.CreateInstance(Namespace.MyClass).UnWrap();

-----------------------------------------

Asp.Net WebSite
    App_Code
      Namespace.MyClass.cs
    Bin
      External.dll

Is that even posible?

I have tried, a lot of posible combinations, like:

Assembly.GetCallingAssembly().CreateInstance("Namespace.MyClass")
Activator.CreateInstance(AppDomain.CurrentDomain,"Namespace","Namespace.MyClass")
Assembly.GetExecutingAssembly().CreateInstance("Namespace.MyClass")
Fraga
  • 1,361
  • 2
  • 15
  • 47

2 Answers2

1

You can use the BuildManager.CodeAssemblies property to list all the assembly names that have been compiled in the App_Code directory. You may be able to accomplish what you need that way.

The problem with App_Code is that everything gets dynamically compiled into an assembly that is by nature, temporary. This comes along with a temporary assembly name. This makes it impossible to hardcode an assembly name or path.

womp
  • 115,835
  • 26
  • 236
  • 269
  • Thanks a lot, here is the complete code for initializing any class in app_code from a dll. Activator.CreateInstance(((Assembly)BuildManager.CodeAssemblies[0]).GetType("Namespace.Class"), ConstructorParams1,ConstructorParams2); – Fraga Apr 15 '10 at 16:32
0

No need use the BuildManager.CodeAssemblies property to list all the assembly names. Instead use:

type="Namespace.MyClass, App_Code" to reference the class.