What should you do?

You upgrade a Windows Forms application to Microsoft .NET Framework 4. The application was developed
by using a previous version of the .NET Framework. The application uses the Code
Access Security (CAS) policy for file access.
When the application is executed, you receive the following exception:
“NotSupportedException: This method uses CAS policy, which has been obsoleted by the .NET Framework.”
You need to resolve the error.
What should you do?

You upgrade a Windows Forms application to Microsoft .NET Framework 4. The application was developed
by using a previous version of the .NET Framework. The application uses the Code
Access Security (CAS) policy for file access.
When the application is executed, you receive the following exception:
“NotSupportedException: This method uses CAS policy, which has been obsoleted by the .NET Framework.”
You need to resolve the error.
What should you do?

A.
Add the following code fragment to the application’s configuration file.
<runtime>
<NetFx40_LegacySecurityPolicy enabled=”true”/> </runtime>

B.
Add the following code fragment to the application’s configuration file. <runtime>
<legacyV1CASPolicy enabled=”true”/>
</runtime>

C.
Add the following code segment to the application’s main method.
AppDomain domain = System.AppDomain.CreateDomain(“MyDomain”);
PolicyLevel polLevel = PolicyLevel.CreateAppDomainLevel();
PermissionSet permSet = new PermissionSet(PermissionState.None);
permSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
domain.ExecuteAssembly(“Assemblies\\MyWindowsExe.exe”);
polLevel.RootCodeGroup.PolicyStatement = new PolicyStatement(permSet);
domain.SetAppDomainPolicy(polLevel);

D.
Add the following code segment to the application’s main method.
PermissionSet requiredSet = new PermissionSet(PermissionState.None);
requiredSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution)); PermissionSet
optionalSet = new PermissionSet(PermissionState.None);
optionalSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read, new string[] { @”c:\temp” }));
PermissionSet deniedSet = new PermissionSet(PermissionState.None);
deniedSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.ControlPolicy)); Console.WriteLine(“\nCurrent permissions granted:”);
PermissionSet permsDenied = null;
foreach(IPermission perm in SecurityManager.ResolvePolicy(evidence, requiredSet, optionalSet, deniedSet, out permsDenied)){}



Leave a Reply 0

Your email address will not be published. Required fields are marked *