Microsoft KB Archive/835464

From BetaArchive Wiki

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)

  1. 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

  2. Start the .NET Framework Configuration tool.
  3. In the left pane, expand Runtime Security Policy, expand Machine, and then expand Code Groups.
  4. Right-click All_Code, and then click New. The Create Code Group dialog box appears.
  5. Click to select the Create a new code group option.
  6. In the Name box, type Test, and then click Next.
  7. To fully trust the strong name of the assembly that contains your J# Browser Control code, follow these steps:
    1. 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.
    2. Locate and then click the assembly that contains your J# Browser Control code, and then click Open.
    3. Click Next.
  8. In the Use existing permission set list, click FullTrust.
  9. Click Next, and then click Finish.

Use the Code Access Security Policy tool (Caspol.exe)

  1. 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

  2. Start the Microsoft Visual Studio .NET 2003 command prompt.
  3. 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
  4. To grant FullTrust permissions to the assembly that contains your J# Browser Controls code, run the following command at the command prompt:

    caspol -addgroup label_value -strong -file AssemblyFileName AssemblyName AssemblyVersion FullTrust -name "Test"

    Notes
    • In the previous command, replace label_value 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.
    • AssemblyFileName, AssemblyName, and AssemblyVersion are placeholders for the file name of your assembly, the display name of your assembly, and the complete version number of your assembly respectively.


STATUS

This behavior is by design.

Keywords: kbpolicy kbconfig kbtrusts kbuidesign kbsecurity kberrmsg kbprb KB835464