System.Security.Permissions.SecurityPermission and Reflection on Godaddy
- by David Murdoch
I have the following method:
public static UserControl LoadControl(string UserControlPath, params object[] constructorParameters)
{
var p = new Page();
var ctl = p.LoadControl(UserControlPath) as UserControl;
// Find the relevant constructor
if (ctl != null)
{
ConstructorInfo constructor = ctl.GetType().BaseType.GetConstructor(constructorParameters.Select(constParam => constParam == null ? "".GetType() : constParam.GetType()).ToArray());
//And then call the relevant constructor
if (constructor == null)
{
throw new MemberAccessException("The requested constructor was not found on : " + ctl.GetType().BaseType.ToString());
}
constructor.Invoke(ctl, constructorParameters);
}
// Finally return the fully initialized UC
return ctl;
}
Which when executed on a Godaddy shared host gives me System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.