locked
CAS Policy - .NET Framework 4 - error at Install RRS feed

  • Question

  • 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.

    Saturday, May 22, 2010 6:58 PM

Answers

All replies

  • Hello Robert,

    Welcome to MSDN forums!

    From VS 2008, VSTO 3.0, we donot use caspol to grant full trust to VSTO assemblies, the video is outofdated. At the moment, we should take this thread as reference:
    http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/1666d2b0-a4d0-41e8-ad86-5eab3542de1e

    And find the proper walkthroughs according to the trageting framework version of your solution.

    Thanks.
     

    Tim Li

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Monday, May 24, 2010 5:33 AM
  • Hi, 

    I am writing to check the status of the issue on your side. Could you please let me know if the suggestion works for you or not? If you have any questions or concerns, please feel free to let me know. I will be more than happy to be of assistance.

     

    Tim Li

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Wednesday, May 26, 2010 3:11 AM
  • Hi Tim, sorry for the late answer.

    The information was useful for me at that time, thank you very much.

    Tuesday, December 21, 2010 7:37 PM