You receive a "System.Security.SecurityException" message when the LinkLabel property runs in a partially-trusted context (820637)



The information in this article applies to:

  • Microsoft Visual Studio 2005 Standard Edition
  • Microsoft Visual Studio 2005 Professional Edition
  • Microsoft Visual Studio 2005 Express Edition
  • Microsoft Visual Studio .NET (2003), Professional Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2003), Academic Edition
  • Microsoft Visual Studio .NET (2002), Professional Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2002), Academic Edition

SYMPTOMS

If you use a LinkLabel control on a localized Windows Form, the application raises the following exception while it tries to deserialize the LinkArea property during run time:
An unhandled exception of type 'System.Security.SecurityException' occurred in mscorlib.dll.

Additional information: Request for the permission of type System.Security.Permissions.SecurityPermission, mscorlib, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
Note In Visual Studio 2005, you will receive the following exception:
Never enter personal information or passwords into a window unless you can verify and trust the source of the request. Source: Unknown Site

CAUSE

The application raises the exception because the LinkArea property cannot be deserialized when the property runs in a partially-trusted context.

WORKAROUND

To work around this problem, set the unrestricted property to True, so that the property runs in a fully-trusted context, as follows.

Microsoft Visual Basic .NET or Microsoft Visual Basic 2005 Code
Imports System.Security.Permissions
<Assembly: PermissionSetAttribute(SecurityAction.RequestMinimum, Name:="Internet")> 
<Assembly: PermissionSetAttribute(SecurityAction.RequestOptional, Unrestricted:=True)> 
Microsoft Visual C# or Microsoft Visual C# 2005 Code
using System.Security.Permissions;
[assembly: PermissionSetAttribute(SecurityAction.RequestMinimum, Name="Internet")]
[assembly: PermissionSetAttribute(SecurityAction.RequestOptional, Unrestricted=true)]

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Create a Windows application by using Visual Basic .NET, Visual Basic 2005, Visual C# 2005, or Visual C# .NET.
  2. Drag a LinkLabel control to Form1.
  3. Right-click Form1, and then click Properties.
  4. In the Properties window, set the Localizable property to True.
  5. Copy the following code, and then paste the code at the top of the AssemblyInfo file, below any IMPORTS statements.

    Visual Basic .NET or Visual Basic 2005 Code
    Imports System.Security.Permissions
    <Assembly: PermissionSetAttribute(SecurityAction.RequestMinimum, Name:="Internet")> 
    <Assembly: PermissionSetAttribute(SecurityAction.RequestOptional, Unrestricted:=False)> 
    Visual C# .NET or Visual C# 2005 Code
    using System.Security.Permissions;
    [assembly: PermissionSetAttribute(SecurityAction.RequestMinimum, Name="Internet")]
    [assembly: PermissionSetAttribute(SecurityAction.RequestOptional, Unrestricted=false)]
  6. On the Debug menu, click Start to run the application.

    You receive the error that is mentioned in the "Symptoms" section of this article.

Modification Type:MajorLast Reviewed:1/27/2006
Keywords:kbvs2005applies kbvs2005swept KbUIDesign kbControl kbWindowsForms kbSecurity kbCtrl kbprb KB820637 kbAudDeveloper