Re: cutome Code Access Permission Attribute Problem
From: Dominick Baier [DevelopMentor] (dbaier_at_pleasepleasenospamdevelop.com)
Date: Thu, 20 Oct 2005 23:12:39 -0700
you are not really building a code access permission, because you implemented
demand yourself - you are not doing a stack walk here - what you are trying
to build is something like PrincipalPermission.
grab a copy of reflector (www.aisto.com/roeder) and have a look at System.Security.Permissions.PrincipalPermission
and see how MS does it.
e.g. you only have to derive from IPermission, ISecurityEncodable
my From/To Xml looks like this:
public void FromXml(SecurityElement e)
string oid = e.Attribute("OperationID");
this._operationId = Convert.ToInt32(oid, CultureInfo.InvariantCulture);
public SecurityElement ToXml()
SecurityElement element = new SecurityElement("IPermission");
Type type = this.GetType();
StringBuilder AssemblyName = new StringBuilder(type.Assembly.ToString());
element.AddAttribute("class", type.FullName + ", " + AssemblyName);
Dominick Baier - DevelopMentor
> Hi Dominick,
> Yes it is 1.1 and i have added it to the "policy assembly" as
> I'm not sure if it is something to do with the de/serialization in
> FromXml/ToXml. attached here is my code. pls see if you can find wny
> Best Regards
> "Dominick Baier [DevelopMentor]"
> <email@example.com> wrote in message
>> Hello Sanjaya,
>> is this 1.1 ?
>> if yes- the assembly containig the perm and attr must be in the
>> list in mscorfg.msc.
>> Your error sounds like a problem with de/serialization in
>> Dominick Baier - DevelopMentor
>>> I have implemented a custom code access permission class and a
>>> corresponding attribute class. I have inherited my permission class
>>> from CodeAccessPermission and the attribute class from
>>> CodeAccessSecurityAttribute class.
>>> I have assign a strong name to the assembly and deploy it to GAC.
>>> when I try to use my custom permission class for imperative
>>> check, it happens successfully. but when I try to use the attribute
>>> class(MyPermissionAttribute) for declarative check, the application
>>> give following compilation error.
>>> "C:\MyTestApp\Form1.cs(197): Error emitting
>>> 'MySecurity.MyPermissionAttribute' attribute -- 'Unexpected
>>> exception processing attribute -- System.ArgumentNullException:
>>> Value cannot be null. Parameter name: child.'
>>> can anyone pls help me to with this?