Sdílet prostřednictvím


Required Changes to Run Office Projects that You Migrate to the .NET Framework 4

If the target framework of an Office project is changed to the .NET Framework 4 from an earlier version of the .NET Framework, you must perform the following tasks to ensure that the solution can run on the development computer and on end user computers:

  • Remove the SecurityTransparentAttribute from the project if you upgraded it from Visual Studio 2008.

  • Perform a Clean command in Visual Studio to be able to run or debug the project on the development computer.

  • Update the .NET Framework prerequisite for the project.

  • End users must also reinstall the solution if you previously deployed it by using ClickOnce before you changed the target framework.

For more information about each of these tasks, see the corresponding sections below.

Removing the SecurityTransparent Attribute from Projects that You Upgrade from Visual Studio 2008

If you upgrade an Office project from Visual Studio 2008 and the target framework of the project subsequently changes to the .NET Framework 4, you must remove the SecurityTransparentAttribute from the project. Visual Studio does not automatically remove this attribute for you. If you do not remove this attribute, the solution will fail to load and the following error will be reported.

"Inheritance security rules violated by type: 'host item class in your project'. Derived types must either match the security accessibility of the base type or be less accessible."

For more information about the conditions in which Visual Studio can change the target framework of an upgraded project to the .NET Framework 4, see Upgrading and Migrating Office Solutions.

To remove the SecurityTransparentAttribute

  1. With the project open in Visual Studio, open Solution Explorer.

  2. Under the Properties node (for C#) or the My Project node (for Visual Basic), double-click the AssemblyInfo code file to open it in the code editor.

    Poznámka

    In Visual Basic projects, you must click the Show All Files button in Solution Explorer to see the AssemblyInfo code file.

  3. Locate the SecurityTransparentAttribute and either remove it from the file or comment it out.

    <Assembly: SecurityTransparent()>
    
    [assembly: SecurityTransparent()]
    

Performing the Clean Command to Debug or Run a Project on the Development Computer

If an Office project was built before the target framework of the project is changed to the .NET Framework 4, you must perform a Clean command and then rebuild the project after the target framework is changed. If do not perform a Clean command, you will receive a COMException when you try to debug or run the retargeted project.

For more information about the Clean command, see Office Solution Build Process Overview.

Updating the Prerequisites for Deployment

When you retarget an Office project to .NET Framework 4, you must also update the corresponding .NET Framework prerequisite in the Prerequisites dialog box. Otherwise, the ClickOnce deployment or Windows Installer Setup project checks for and installs a previous version of the .NET Framework.

For more information about updating the prerequisites for deployment to end user computers, see How to: Install Prerequisites on End User Computers to Run Office Solutions.

Reinstalling Solutions on End User Computers

If you use ClickOnce to deploy an Office solution that targets the .NET Framework 3.5 and then you retarget the project to the .NET Framework 4, end users must uninstall the solution and then reinstall the solution after you republish it. If you republish the retargeted solution and the solution is updated on end user computers, end users will receive a COMException when they run the updated solution.

For more information about uninstalling solutions, see How to: Uninstall a ClickOnce Office Solution.

See Also

Concepts

Migrating Office Solutions to the .NET Framework 4

Change History

Date

History

Reason

May 2010

Added section about removing SecurityTransparentAttribute from projects upgraded from Visual Studio 2008.

Information enhancement.