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

Article translations Article translations
Article ID: 820637 - View products that this article applies to.
Expand all | Collapse all

On This Page

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.

Properties

Article ID: 820637 - Last Review: January 27, 2006 - Revision: 2.2
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
  • Microsoft Visual Studio .NET 2003 Enterprise Developer
  • Microsoft Visual Studio .NET 2003 Academic Edition
  • Microsoft Visual Studio .NET 2002 Professional Edition
  • Microsoft Visual Studio .NET 2002 Enterprise Architect
  • Microsoft Visual Studio .NET 2002 Enterprise Developer
  • Microsoft Visual Studio .NET 2002 Academic Edition
Keywords: 
kbvs2005applies kbvs2005swept kbuidesign kbcontrol kbwindowsforms kbsecurity kbctrl kbprb KB820637

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com