views:

51

answers:

2

I am trying to load a user control dynamically using this code:

UserControl homePageContent = Page.LoadControl(userControlPath) as UserControl;

I get the following error on the above line when the trust level is Medium:

 System.Security.SecurityException: Request failed. 
 at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
 at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)...

Is it really not possible to load a user control dynamically in a Medium Trust environment?

Edit: Putting DLL in GAC is also not allowed.

Thanks in advance!

A: 

If you sign the DLL and place it in the GAC, it may work.

Although there is probably a better way to do it.

Shiraz Bhaiji
A: 

Its surely supported in medium trust. I think there is some other problem. i have used it many times

eg:

UserControl ctl = Page.LoadControl("~/COntrols/Control.ascx") as UserControl;

Priyan R
Can you please tell me how you could rectify the `SecurityException` there?
Vijay
Don't knpw whats really it is, its supported in medium trust, but i think there is some other permission causing the problem
Priyan R