On Fri, 12 Apr 2002 08:46:12 -0500, Dave Serrano <[EMAIL PROTECTED]>
wrote:

<snip/>

>My question deals with if I want to change to the 'SecurityAction' from
>'LinkDemand' to 'Demand'.  Something like this:
>
><StrongNameIdentityPermissionAttribute(SecurityAction.Demand, _
>PublicKey:="002400000480000094000...")> _
>Public Class myClass
>...
>
>
>I guess my assumption was that if I used 'SecurityAction.Demand' the CLR
>would walk up the stack and check the private key of all assemblies in the
>stack and throw an exception if one didn't match.  This assumption is
>obviously wrong.  Even my most basic application of a simple Winform
>instantiating the class fails when I use 'Demand' rather
than 'LinkDemand'.
>I get the following error:
>
>"Request for the permission of type
>System.Security.Permissions.StrongNameIdentityPermission, mscorlib,
>Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
>failed."
>
>
>Can someone explain why the 'LinkDemand' but not the 'Demand' works for
the
>same application?

My guess is that you're trying to instantiate myClass from a button event
or something like that.  In that case, the problem is that your button's
event code is not the only caller in the stack.  I reproduced your problem
on my machine by creating a class that has a method "protected" by a
strong name.  When I try to create an instance of the class that contains
the method, I get the error you see, and here's the call stack:

System.Security.SecurityException: Request for the permission of type
System.Security.Permissions.StrongNameIdentityPermission, mscorlib,
Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
failed.
   at System.Security.CodeAccessSecurityEngine.CheckTokenBasedSetHelper
(Boolean ignoreGrants, TokenBasedSet grants, TokenBasedSet denied,
TokenBasedSet demands)
   at System.Security.CodeAccessSecurityEngine.CheckSetHelper
(PermissionSet grants, PermissionSet denied, PermissionSet demands)
   at StrongNameDemand.SND.CallMe()
   at StrongNameDemandTest.frmMain.btnCall_Click(Object sender, EventArgs
e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

Since none of the methods before my btnCall_Click have the desired strong
name, it fails.  If I do the same thing from a Main method in a console
app, the call succeeds.

Regards,

Jason

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to