Hi folks,
I have the following situation:
- MyApplication.exe is an WinForms-application that is signed with
"AppKey.snk".
- MyControls.dll contains a MyComponent-class that I want to drop on a form
on the application. This assembly is signed with "ControlsKey.snk"
I don't want anyone else using the control from MyControl.dll except
MyApplication.exe, or any other application that would be signed with
"AppKey.snk".
Browsing through the newsgroups via Google, I got the understanding
StrongNameIdentityPermission with LinkDemand-action would be the way to go,
as that would require the immediate caller of MyComponent-class (which
should be MyApplication) to be signed with a specfic key-pair. So I have
done the declarative security on MyComponent-class like this:
<StrongNameIdentityPermission(SecurityAction.LinkD emand, _
PublicKey:="00240000048000009400000006020000002400 0052534131000400" & _
"0001000100bfb4cb9b5d7c4d678b835fafd56d6bdba74774d 3c5f6" & _
"38f2261885275fabefd93be9f7c5a5f4c7e1802313185263e ff0f5" & _
"23f4f6e54e4fd38375ab64257fe484609d237a6508746faa9 f929a" & _
"03eac98c6297955e8649bf3a660c2f1a2117001699d42ca00 b572a" & _
"d69a005de4141273bbc93fbe670e101be349076074facc5fb 6")> _
Public Class MyComponent
Inherits System.ComponentModel.Component
.....etc...
The Hex-string contains the public key from AppKey.snk.
Here is the problem: When I run my MyApplication I always get an exception
on the "InitializeComponent"-call on my application, i.e. in the designer
generated constructor:
Public Sub New()
MyBase.New()
Try
'This call is required by the Windows Form Designer.
InitializeComponent() <-- Debugger stops here, if "break on
exception" is on.
'Add any initialization after the InitializeComponent() call
Catch ex As Exception
Windows.Forms.MessageBox.Show(ex.Message, "Exception")
End Try
End Sub
The exception message is:
"Request for the permission of type
System.Security.Permissions.StrongNameIdentityPerm ission, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
failed."
And stacktrace is:
" at MyApplication.MainForm.InitializeComponent()
at Myapplication.MainForm..ctor() in
C:\Work\MyApplication\Source\MainForm.vb:line 23"
Now why does that happen? I would understand if I would use Demand-action on
the permission but why can't I get the LinkDemand to work? Should I do some
declarative stuff on MyApplication as well?
Regards,
- Petri