Hi
I am trying to protect a class from being used by anything other than the application for which it was intended with StrongNameIdentityPermission using declarative code access security
In my solution, I have a Windows Forms Project called MainApp which I have signed with a strong name key. I also have a Class Library Project called CallClass, which I have signed with the same key
CallClass contains one class called MyClass which is coded as follows :
[StrongNameIdentityPermission(SecurityAction.LinkDe mand, PublicKey="<public key>", Name="MainApp.exe", Version="1.0.0.0")
public class MyClas
public MyClass(
public static string LogonSucceed(
return "This message indicates the logon process succeeded."
I obtained the public key by running sn -Tp against the .snk file
MainApp has a reference to CallClass, and contains 1 Win Form called MainForm. The Load Event for MainForm is coded as follows :
private void MainForm_Load(object sender, System.EventArgs e
try
MessageBox.Show(MyClass.LogonSucceed())
catch (SecurityException ex
MessageBox.Show("MyClass is unavailable. " + ex.Message)
Application.Exit()
When I run this app in VS.NET 2003, I receive the following error :
Request for the permission of type System.Security.Permissions.StrongNameIdentityPerm ission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=<public key token> failed
Note that the stack trace for the exception and manual tracing indicate that the exception occurs before any code within MainForm_Load is actually run
My understanding is that an exception will occur when you specify a Security Action of Demand in the attribute, because a full stack walk is performed and all callers, all the way back to mscorlib are expected to have been signed with the same strong name key
However, I am using LinkDemand, which should only require the immediate caller to be signed with the key
Note that I have also posted this one to the dotnet.security group. But I thought I'd post it here too just in case
Any help you could provide to solve this problem would be much appreciated
Thanks
David Riddiford