Skip to content

Commit 91a8225

Browse files
authored
Remove CAS attributes (#8012)
1 parent 2403570 commit 91a8225

File tree

25 files changed

+61
-121
lines changed

25 files changed

+61
-121
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Library</OutputType>
4+
<TargetFrameworks>net4.8</TargetFrameworks>
5+
</PropertyGroup>
6+
</Project>

snippets/csharp/System.Runtime.Hosting/ActivationArguments/Overview/program.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@
55
using System.Security.Policy;
66
using System.Reflection;
77
using System.Security;
8-
using System.Security.Permissions;
98
using System.Runtime.Hosting;
109

1110
namespace ActivationContextSample
1211
{
1312
public class Program : MarshalByRefObject
1413
{
15-
[SecurityPermission(SecurityAction.LinkDemand, ControlDomainPolicy=true)]
1614
public static void Main(string[] args)
1715
{
1816
//<Snippet2>
@@ -35,7 +33,7 @@ public static void Main(string[] args)
3533
//</Snippet4>
3634
Console.Read();
3735
}
38-
[SecurityPermission(SecurityAction.LinkDemand, ControlDomainPolicy=true)]
36+
3937
public void Run()
4038
{
4139
Main(new string[] { });
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Library</OutputType>
4+
<TargetFrameworks>net6.0-windows</TargetFrameworks>
5+
<UseWindowsForms>true</UseWindowsForms>
6+
</PropertyGroup>
7+
</Project>

snippets/csharp/System.Runtime.InteropServices/GCHandle/Overview/sample.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Threading;
55
using System.Windows.Forms;
66
using System.Runtime.InteropServices;
7-
using System.Security.Permissions;
87

98
public delegate bool CallBack(int handle, IntPtr param);
109

@@ -24,7 +23,6 @@ public static void Main()
2423
Run();
2524
}
2625

27-
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
2826
public static void Run()
2927
{
3028
TextWriter tw = Console.Out;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>

snippets/csharp/System.Runtime.InteropServices/SafeHandle/Overview/program.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
using System.Runtime.InteropServices;
44
using System.IO;
55
using System.ComponentModel;
6-
using System.Security.Permissions;
76
using System.Security;
87
using System.Threading;
98
using Microsoft.Win32.SafeHandles;
109
using System.Runtime.ConstrainedExecution;
10+
using System.Security.Permissions;
1111

1212
namespace SafeHandleDemo
1313
{
14-
[SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode = true)]
15-
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
1614
internal class MySafeFileHandle : SafeHandleZeroOrMinusOneIsInvalid
1715
{
1816
// Create a SafeHandle, informing the base class
@@ -125,7 +123,6 @@ public void Dispose() // Follow the Dispose pattern - public nonvirtual.
125123
// if it hasn't already been disposed.
126124
// However, there may be a need for a subclass to
127125
// introduce a finalizer, so Dispose is properly implemented here.
128-
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
129126
protected virtual void Dispose(bool disposing)
130127
{
131128
// Note there are three interesting states here:
@@ -142,7 +139,6 @@ protected virtual void Dispose(bool disposing)
142139
// SafeHandle records the fact that we've called Dispose.
143140
}
144141

145-
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
146142
public byte[] ReadContents(int length)
147143
{
148144
if (_handle.IsInvalid) // Is the handle disposed?

snippets/csharp/System.Runtime.InteropServices/SafeHandle/Overview/safehandle.csproj

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
22
<PropertyGroup>
33
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
44
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -9,6 +9,13 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>SafeHandle</RootNamespace>
1111
<AssemblyName>SafeHandle</AssemblyName>
12+
<FileUpgradeFlags>
13+
</FileUpgradeFlags>
14+
<UpgradeBackupLocation>
15+
</UpgradeBackupLocation>
16+
<OldToolsVersion>2.0</OldToolsVersion>
17+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
18+
<TargetFrameworkProfile />
1219
</PropertyGroup>
1320
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1421
<DebugSymbols>true</DebugSymbols>
@@ -19,6 +26,7 @@
1926
<ErrorReport>prompt</ErrorReport>
2027
<WarningLevel>4</WarningLevel>
2128
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
29+
<Prefer32Bit>false</Prefer32Bit>
2230
</PropertyGroup>
2331
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2432
<DebugType>pdbonly</DebugType>
@@ -28,6 +36,7 @@
2836
<ErrorReport>prompt</ErrorReport>
2937
<WarningLevel>4</WarningLevel>
3038
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
39+
<Prefer32Bit>false</Prefer32Bit>
3140
</PropertyGroup>
3241
<ItemGroup>
3342
<Reference Include="System" />
@@ -38,6 +47,9 @@
3847
<Compile Include="Program.cs" />
3948
<Compile Include="Properties\AssemblyInfo.cs" />
4049
</ItemGroup>
50+
<ItemGroup>
51+
<None Include="app.config" />
52+
</ItemGroup>
4153
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
4254
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
4355
Other similar extension points exist, see Microsoft.Common.targets.

snippets/csharp/System.Runtime.Serialization/FormatterServices/CheckTypeSecurity/FormatterServices.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Runtime.Serialization.Formatters;
88
using System.Runtime.Serialization.Formatters.Binary;
99
using System.Reflection;
10-
using System.Security.Permissions;
1110

1211
// Person is a serializable base class.
1312
[Serializable]
@@ -55,7 +54,6 @@ public Manager() : base("Employee")
5554
}
5655

5756
//<snippet2>
58-
[SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
5957
public void GetObjectData(SerializationInfo info, StreamingContext context)
6058
{
6159

@@ -96,10 +94,8 @@ private void DisplaySerializationInfo(SerializationInfo info)
9694
}
9795
//</snippet3>
9896

99-
[SecurityPermissionAttribute(SecurityAction.Demand, Flags=SecurityPermissionFlag.SerializationFormatter)]
10097
protected Manager(SerializationInfo info, StreamingContext context) : base(null)
10198
{
102-
10399
// Get the set of serializable members for the class and base classes.
104100
Type thisType = this.GetType();
105101
MemberInfo[] mi = FormatterServices.GetSerializableMembers(thisType, context);
@@ -160,4 +156,4 @@ public static void Run()
160156
// Name=Employee+title, ObjectType=System.String, Value=Employee
161157
// Name=Person+title, ObjectType=System.String, Value=Person
162158
// Manager -> Employee -> Person
163-
//</snippet1>
159+
//</snippet1>

snippets/csharp/System.Runtime.Serialization/FormatterServices/GetObjectData/Populate.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
using System.Runtime.Serialization;
55
using System.IO;
66
using System.Reflection;
7-
using System.Security.Permissions;
87

9-
[assembly: SecurityPermission(SecurityAction.RequestMinimum)]
108
namespace Examples
119
{
1210
// The SerializableAttribute specifies that instances of the class
@@ -25,7 +23,6 @@ public Book(string newTitle, string newAuthor)
2523
}
2624
}
2725

28-
[SecurityPermission(SecurityAction.Demand)]
2926
public sealed class Test
3027
{
3128
public static void Main()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Library</OutputType>
4+
<TargetFrameworks>net4.8</TargetFrameworks>
5+
</PropertyGroup>
6+
</Project>

0 commit comments

Comments
 (0)