Microsoft KB Archive/835464

= A System.SecurityException exception occurs when you use Swing components in J# Browser Controls =

Article ID: 835464

Article Last Modified on 5/18/2007

-

APPLIES TO


 * Microsoft Visual J# .NET 2003 Standard Edition

-



SYMPTOMS
When you run a Microsoft J# Browser Control that uses Swing components, a System.SecurityException exception occurs.

Note Swing components are implemented in the Microsoft Supplemental UI Library for Visual J# .NET 1.1 (Vjssupuilib.dll).



CAUSE
From a partially trusted assembly, you cannot call assemblies that allow only fully trusted assemblies to call them. From a partially trusted assembly, when you try to call assemblies that allow only fully trusted assemblies to call them, a System.SecurityException exception occurs.

By default, J# Browser Controls are only partially trusted. The Supplemental UI Library for Visual J# .NET 1.1 allows only fully trusted assemblies to call it. Therefore, when you use Swing components in J# Browser Controls, a System.SecurityException exception occurs.

Note You can use the AllowPartiallyTrustedCallers attribute to allow your full-trusted library to be called by partially trusted code.



WORKAROUND
To work around this behavior, change the security policy for your computer so that the assembly that contains your J# Browser Control code is fully trusted. To do this, sign the assembly with a strong name, and then make this strong name fully trusted. To do this, use either of the following methods:

Use the Microsoft .NET Framework Configuration tool (Mscorcfg.msc)
 Sign the assembly that contains your J# Browser Control code with a strong name.

For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

321917 HOW TO: Create a strong named assembly in Visual J# .NET

 Start the .NET Framework Configuration tool. In the left pane, expand Runtime Security Policy, expand Machine, and then expand Code Groups. Right-click All_Code, and then click New. The Create Code Group dialog box appears. Click to select the Create a new code group option. In the Name box, type Test, and then click Next. To fully trust the strong name of the assembly that contains your J# Browser Control code, follow these steps: <ol style="list-style-type: lower-alpha;"> In the Choose the condition type for this code group list, click Strong Name, and then click Import. The Import Strong Name From Assembly dialog box appears.</li> Locate and then click the assembly that contains your J# Browser Control code, and then click Open.</li> Click Next.</li></ol> </li> In the Use existing permission set list, click FullTrust.</li> Click Next, and then click Finish.</li></ol>

Use the Code Access Security Policy tool (Caspol.exe)
<ol> Sign the assembly that contains your J# Browser Control code with a strong name.

For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

321917 HOW TO: Create a strong named assembly in Visual J# .NET

</li> Start the Microsoft Visual Studio .NET 2003 command prompt.</li> Run the following command to obtain the value of the label of the All_Code code group, and then note down this value:

caspol -listgroups </li> To grant FullTrust permissions to the assembly that contains your J# Browser Controls code, run the following command at the command prompt:

caspol -addgroup  -strong -file     FullTrust -name &quot;Test&quot;

Notes <ul> In the previous command, replace  with the value of the label of the All_Code code group. This value is the same as the value that you noted down in step 3.</li> , , and   are placeholders for the file name of your assembly, the display name of your assembly, and the complete version number of your assembly respectively.</li></ul> </li></ol>

<div class="status_section">

STATUS
This behavior is by design.

<div class="references_section">