System.Security.Permissions.SecurityPermission and Reflection on Godaddy

Posted by David Murdoch on Stack Overflow See other posts from Stack Overflow or by David Murdoch
Published on 2010-05-26T17:59:15Z Indexed on 2010/05/26 18:01 UTC
Read the original article Hit count: 411

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.

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET