Re: StrongNameIdentityPermission issue.

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


Date: Wed, 28 Apr 2004 18:16:02 -0700

Thanks Hernan,

I checked the versions of my assemblies and they were all 1.0.0.0 (well actually they are 1.0.0 in AssemblyInfo.cs but this seems to translate to 1.0.0.0 when you retrieve FullName property of the Assembly).

I looked at mscorlib.dll and its version was 1.0.5000.0. Out of interest, I tried changing the link demand to point at mscorlib and system.windows.forms. And I also tried a link demand for MainApp with a version of 1.0.5000.0, although I expected this wouldn't work. None of these tries worked.

I can only assume that when instantiating a form, another assembly is called which in turn calls the constructor of my form class in the CallClass assembly, thus spoiling the Link Demand. What assembly that is, I don't know, because when I remove the link demand and run GetCallingAssembly from the form constructor, it points to my MainApp assembly.

The error which displays mscorlib is confusing because I am not making a link demand for this, but for my MainApp assembly.

I'd be interested to know if anyone can make the scenario I described below work.
     
     ----- Hernan de Lahitte wrote: -----
     
     Check the assembly version number where your Forms resides. Version numbers
     must be the same on both the asembly and on the linkdemand declaration. Your
     exception shows a version number of "1.0.5000.0" and on your LinkDemand
     declaration is "1.0.0.0".
     
     --
     Hernan de Lahitte
     Lagash Systems S.A.
     http://weblogs.asp.net/hernandl
     
     
     This posting is provided "AS IS" with no warranties, and confers no rights.
     
     "David Riddiford" <anonymous@discussions.microsoft.com> wrote in message
     news:1F50C7F9-5AB1-493E-A433-BA5B95EA82E5@microsoft.com...
> 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.