none
CAS Policy - .NET Framework 4 - error at Install

    Pregunta

  • I would like to install an AddIn created in Visual Studio 2010 and am not able to get past following error which pops up when installing the setup project:

    Error1001. This method explicitly uses CAS policy, which has been obsoleted by the .NET Framework. In order to enable CAS Policy for compatibility reasons,

    please use the NetFx40_LegacySecurityPolicy configuration switch. Please see http://go.microsoft.com/fwlink/?LinkID=155570 for more information.

    Please let me know if something is being missed here.


    What was tested:

    - added App.config.file -> at build the file "CustomSetupActions.dll.config" is created

    This file contains:
    <configuration>
     <runtime>  
     <NetFx40_LegacySecurityPolicy enabled="true" />
      </runtime>
    </configuration>

     

    - building AddIn is activating the AddIn as expected

     

    - added below code following the below referenced video

    Video:
    http://msdn.microsoft.com/en-us/office/bb851702.aspx


    - Read following posts

    Previous post:
    http://social.msdn.microsoft.com/forums/en-US/vsto/thread/91ce9734-a424-4d3b-ab83-6506a9424f24/

    --> added the adapted long string to the CustomActionData  property


    Post
    http://social.msdn.microsoft.com/Forums/en-US/vststest/thread/3e520735-8ced-4092-b681-38b69e0db534/

    - on this blog http://blogs.rev-net.com/ddewinter/

    the option <trust legacyCasModel="true"/> is described:


    --> added it to the App.config file


    Code:

    public override  void Install(System.Collections.IDictionary stateSaver)
            {

                PolicyLevel ent;
                PolicyLevel mach;
                PolicyLevel user;
                String sAssemblyPath = this.Context.Parameters["custAssembly"]; 
               
               

                IEnumerator policyEnumerator =  SecurityManager.PolicyHierarchy(); 

     

                policyEnumerator.MoveNext();
                ent = (PolicyLevel)Convert.ChangeType(policyEnumerator.Current, typeof(PolicyLevel));


                policyEnumerator.MoveNext();
                mach = (PolicyLevel)Convert.ChangeType(policyEnumerator.Current, typeof(PolicyLevel));

                policyEnumerator.MoveNext();
                user = (PolicyLevel)Convert.ChangeType(policyEnumerator.Current, typeof(PolicyLevel));

                PermissionSet fullTrust = user.GetNamedPermissionSet("FullTrust");
                PolicyStatement policy =  new PolicyStatement(fullTrust, PolicyStatementAttribute.Nothing );
              

                UrlMembershipCondition condition = new UrlMembershipCondition(sAssemblyPath);
                CodeGroup group = new UnionCodeGroup(condition, policy);


                group.Name = "ExcelAddIn8";
                user.RootCodeGroup.AddChild(group);

                SecurityManager.SavePolicy();
                base.Install(stateSaver);

            }


    Thank you for the help.

    sábado, 22 de mayo de 2010 18:58

Respuestas

Todas las respuestas