Skip to main content Skip to footer

ComponentOne Controls in ClickOnce and Partial Trust Applications

Applies To:

Studio Enterprise


Bernardo Castilho

Published On:


ClickOnce is a new feature in Visual Studio 2005 and .NET 2.0 that allows you to deploy WinForms applications to the web, ftp, or network servers directly from Visual Studio. Users can simply click a link to install and run the application on their computers. This makes application deployment extremely easy.

Besides easy installation, ClickOnce deployment includes support for automatic updates, security configuration, and run once or full install deployment. The main limitation is that since the installation procedure is automatic, you can't customize it. However, you can add configuration steps to the application itself if necessary.

The security configuration options available to ClickOnce are flexible and easy to use. Under the .NET Framework 1.x, configuring WinForms applications to run with partial trust was fairly difficult. It required using the Code Access Security configuration tool to grant one or more controls custom permissions. Determining which permissions were required was very difficult, so most applications probably ended up granting full trust to all controls they needed (the .NET installation grants Microsoft controls full trust by default).

For details on ClickOnce, see the article at:


Deploying applications from the development machine to the server is called publishing, to distinguish it from deploying it from the server to client machines.

Using ClickOnce to publish applications is easy. After building your project in Visual Studio, right-click the project name in the Solution Explorer window and select Properties, then select the Publish tab.

This page allows you to select the location where the application will be deployed, the files that need to be installed, update and install options, and deployment versioning. The Publish Now button publishes the application to the selected location and brings up a page with a link so you can test the installation.

By default, ClickOnce configures applications to run with full trust. This may not be acceptable in some cases. For example, users may want to prevent the application from accessing the file system or network resources.

To configure the application permissions, use the Security tab.

This dialog allows you to enable the ClickOnce security settings, to specify whether the application should run with full or partial trust, and to specify which permissions should be granted or denied.

The first control in the Security Permissions group specifies where the application will be installed from, which automatically selects a default set of permissions displayed in the list below.

Each item on the list represents a set of permissions. The green checkmarks in the Included column indicate that the default permissions on that set will be granted to the application. Blanks indicate no permissions on that set will be granted. You can customize each set of permissions by clicking the Properties button.

All controls that ship with Visual Studio are configured to run with full trust by default, so if your application only uses these controls, you probably won't have to customize the default permissions.

Most other WinForms controls will require you to add a few additional permissions. For example, licensed controls typically need to use serialization and reflection to read the licensing information embedded in the application resources. Many controls call Windows APIs to provide advanced features not provided in the .NET Framework and thus need permission to call unmanaged code.

Finding out which permissions are required by the application is easy. The Calculate Permissions button should do this, but it is not reliable since it seems to examine all the code in all of the application assemblies, including methods that are never actually called by the application. Instead, simply run the application in debug mode. If the application needs a permission that it doesn't have, an exception will be thrown:

Unfortunately, the error message is not very specific. But if you click the Add Permission to the project link, the permission will be added to the app.manifest file in the Properties project folder. You can then re-run the project, and if more permissions are required, grant them one by one.

Once the project has all the required permissions, it will run. You can then go back to the Security tab and review the permissions to make sure they are reasonable.

For example, a simple application with a form and a C1FlexGrid control in it requires some additional security permissions:

The warning sign next to the SecurityPermission item indicates that additional permissions were granted in that group. Click the Properties button so see the current configuration for the group:

The added permissions are highlighted.

The first one, Allow calls to unmanaged assemblies, is required because the grid uses Windows API calls to manage its window styles and scrollbars. The other three permissions are required to read and validate the licensing information stored in the application assembly.

It is unfortunate that the very general and potentially dangerous permission to execute unmanaged code is needed to perform basic and entirely safe tasks like scrolling windows efficiently or setting window styles.

But the permission is not granted directly to the control. Instead, it is granted to the application. Other applications using the same control may not be granted this permission. This is an important new security feature in version 2.0 of the .NET Framework.

Running partial trust applications without ClickOnce is a lot more complicated. The process is described below, but if you are happy with the ClickOnce method, there's no need to read any further.

Instead of using Visual Studio to configure the permissions, you have to use the Microsoft .NET Configuration Tool, which can be found in the Windows Control Panel under Administrative Tools. This is what the tool looks like:

To see how the tool works, start by disabling the ClickOnce security settings in the application you created earlier (or create a new application).

Next, to simulate deployment to a partial trust environment, right-click the Runtime Security Policy node and select the Adjust Security option. Click the Next button and then use the slider to reduce the trust assigned to the My Computer zone:

If you run the application now, it will throw a security exception because the grid doesn't have all the permissions it needs.

To grant the permissions, right-click the My Computer Zone node and select New to add a new code group. Name the new group C1FlexGrid.

Click Next to define the membership condition for the new code group. Select Strong Name from the list, then click the Import button and select the C1FlexGrid control:

Click Next to define the permission set to assign to the new group, then select Create a new permission set. Click Next, then name the new permission set C1FlexGrid. Click Next one more time to select the permissions:

Select the Security item, then click Add to add the permissions. Then select the following options:

Click OK to close the dialog and click Next to finish the wizard.

This last step is the most difficult part of the security configuration. With ClickOnce and Visual Studio 2005, you can run the application and add the needed permissions one at a time. Without ClickOnce, you need to get the list of required permissions from the control vendor, or use trial-and-error to get a set of permissions that works.

Note that the control will get the permissions you specify explicitly on the new code group plus those granted by all parent nodes (in this case the medium trust permissions).

Try running the application again and this time it will run without problems.

When you are satisfied with the new code groups and permission sets, right-click the Runtime Security Policy node and select Create Deployment Package from the context menu. This will create a deployment package that must be installed by the user (or, at the enterprise level, by a network administrator).

When you are done testing, be sure to restore the permissions necessary to do your work. To reset all of the security nodes and permissions to their default values, right-click the Runtime Security Policy node and select Reset All from the context menu.


comments powered by Disqus