How to: Preview and Debug Managed Code Form Templates that Require Full Trust

By default, if you attempt to debug or preview a managed-code project that contains code that invokes an object model member that requires full trust, such as the LoginName property which requires access to information about the user's login domain, Microsoft Office InfoPath 2007 will display the following error messages.

When previewing:

"An unhandled exception has occurred in the form's code." Followed by, "InfoPath cannot complete this action, because of an error in the form's code."

When debugging:

Focus will move to the line of code in the code editor that is calling the member that requires full trust, and the following message will be displayed: "SecurityException was unhandled by user code - Request failed".

To allow the form template's business logic to call this member when it is being debugged or previewed, you must set your form template's security level to Full Trust as described in the following procedure.

Configuring a Managed Code Form Template that Requires Full Trust

Set your form's security level to Full Trust

  1. If you are working in InfoPath, open the form template in design mode.

    If you are working in Visual Studio, open the InfoPath Form Template project, and then click the manifest.xsf [Design] tab to display the form designer.

  2. On the Tools menu, click Form Options.

  3. In the Category list, click Security and Trust.

  4. Under Security Level, clear Automatically determine security level.

  5. Select Full Trust, and then click OK.

After this procedure is performed, you can debug your project as described in How to: Preview and Debug InfoPath Managed Code Form Templates.

Note

Successfully deploying a managed code form template that requires full trust requires additional steps, such as digitally signing, or installing and registering the form template. For information on deploying a managed code form template after it is debugged see, How to: Deploy InfoPath Projects.

See Also

Concepts

How to: Preview and Debug InfoPath Managed Code Form Templates
How to: Deploy InfoPath Projects