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:
- 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.
- Locate and then click the assembly that contains your J# Browser Control code, and then click Open.
- Click Next.
- In the Use existing permission set list, click FullTrust.
- Click Next, and then click Finish.
Use the Code Access Security Policy tool (Caspol.exe)
- 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 Microsoft Visual Studio .NET 2003 command prompt.
- 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 - To grant FullTrust permissions to the assembly that contains your J# Browser Controls code, run the following command at the command prompt:
caspol -addgrouplabel_value
-strong -fileAssemblyFileName
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
, andAssemblyVersion
are placeholders for the file name of your assembly, the display name of your assembly, and the complete version number of your assembly respectively.
- In the previous command, replace
STATUS
This behavior is by design.
REFERENCES
For more information, visit the following Microsoft Developer Network (MSDN) Web sites:
http://msdn2.microsoft.com/en-us/library/system.security.securityexception(vs.71).aspx
http://msdn2.microsoft.com/en-us/vjsharp/bb188695.aspx
http://msdn2.microsoft.com/en-us/library/fkytk30f(vs.71).aspx
http://msdn2.microsoft.com/en-us/library/2bc0cxhc(vs.71).aspx
http://msdn2.microsoft.com/en-us/library/cb6t8dtz(vs.71).aspx
http://msdn2.microsoft.com/en-us/library/8skskf63(vs.71).aspx
http://msdn2.microsoft.com/en-us/library/system.security.allowpartiallytrustedcallersattribute(vs.71).aspx
Keywords: kbpolicy kbconfig kbtrusts kbuidesign kbsecurity kberrmsg kbprb KB835464