StrongNameIdentityPermission issue.

From: David Riddiford (anonymous_at_discussions.microsoft.com)
Date: 04/28/04


Date: Tue, 27 Apr 2004 23:01:06 -0700

Hi,

I am having another problem with StrongNameIdentityPermission. I'll go through an example.

I have two projects in a solution: MainApp and CallClass. MainApp is a WinForm project containing a form called MainForm. CallClass is a class library project containing a class called MyClass and a Form called SecondForm. MyClass has a public static method called LogonSucceed which simply returns a string.

Both projects are strong named.

Both classes in CallClass have the following strong name identity permission demand:
[StrongNameIdentityPermission(SecurityAction.LinkDemand, PublicKey="<public key>", Name="MainApp", Version="1.0.0.0")]

The load method of MainForm is as follows:
private void MainForm_Load(object sender, System.EventArgs e)
{
        try
        {
                MessageBox.Show(MyClass.LogonSucceed());
                Form secondForm = new SecondForm();
                secondForm.Owner = this;
                secondForm.Show();
        }
        catch (SecurityException ex)
        {
                MessageBox.Show("MyClass is unavailable. " + ex.Message);
                Application.Exit();
        }
}

When I run the app, the message box displays correctly, but when SecondForm is instantiated, a security exception occurs as follows:
Request for the permission of type System.Security.Permissions.StrongNameIdentityPermission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=<public key token> failed.

Exactly the same Link Demand is performed on both classes in the CallClass project. The call to a public static method works. Instantiating the form fails. Note that I checked that instantiating MyClass actually worked. Also, if I remove the name and version parameters to the strong name identity permission, instantiating the form will work.

So it appears that StrongNameIdentityPermission does not work on WinForm classes if the name and version parameters are set, unless of course I am doing something wrong :-)

Does anyone have any ideas as to why this behaviour is occuring, and how I can resolve this issue.

Thanks,
David.