Skip to content

Commit bb47b47

Browse files
authored
Remove CAS attributes (#8011)
1 parent af4374a commit bb47b47

File tree

23 files changed

+190
-182
lines changed

23 files changed

+190
-182
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/ActivationContext/Overview/program.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
//<Snippet1>
22
using System;
3-
using System.Collections;
4-
using System.Text;
5-
using System.Security.Policy;
6-
using System.Reflection;
7-
using System.Security;
8-
using System.Security.Permissions;
93

104
namespace ActivationContextSample
115
{
126
public class Program : MarshalByRefObject
137
{
14-
[SecurityPermission(SecurityAction.LinkDemand, ControlDomainPolicy=true)]
158
public static void Main(string[] args)
169
{
1710
//<Snippet3>
@@ -25,7 +18,7 @@ public static void Main(string[] args)
2518

2619
Console.Read();
2720
}
28-
[SecurityPermission(SecurityAction.LinkDemand, ControlDomainPolicy=true)]
21+
2922
public void Run()
3023
{
3124
Main(new string[] { });

snippets/csharp/System/AppDomain/UnhandledException/unhandledexception.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// <Snippet1>
22
using System;
3-
using System.Security.Permissions;
43

54
public class Example
65
{
7-
[SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlAppDomain)]
86
public static void Main()
97
{
108
AppDomain currentDomain = AppDomain.CurrentDomain;
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/AppDomainManager/Overview/customAppDomainManager.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using System.Net;
1212
using System.Reflection;
1313
using System.Security;
14-
using System.Security.Permissions;
1514
using System.Security.Policy;
1615
using System.Security.Principal;
1716
using System.Threading;
@@ -22,10 +21,6 @@
2221
namespace MyNamespace
2322
{
2423
[GuidAttribute("F4D15099-3407-4A7E-A607-DEA440CF3891")]
25-
[SecurityPermissionAttribute(SecurityAction.LinkDemand,
26-
Flags = SecurityPermissionFlag.Infrastructure)]
27-
[SecurityPermissionAttribute(SecurityAction.InheritanceDemand,
28-
Flags = SecurityPermissionFlag.Infrastructure)]
2924
public class MyAppDomainManager : AppDomainManager
3025
{
3126
private HostSecurityManager mySecurityManager = null;
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/ApplicationId/Overview/program.cs

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

109
namespace ActivationContextSample
1110
{
1211
public class Program : MarshalByRefObject
1312
{
14-
[SecurityPermission(SecurityAction.Demand, ControlDomainPolicy = true)]
1513
public static void Main(string[] args)
1614
{
1715
//<Snippet2>
@@ -57,4 +55,4 @@ public void Run()
5755
}
5856
}
5957
}
60-
//</Snippet1>
58+
//</Snippet1>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Library</OutputType>
4+
<TargetFrameworks>net4.8</TargetFrameworks>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<Reference Include="System.Runtime.Serialization.Formatters.Soap" />
8+
</ItemGroup>
9+
</Project>

snippets/csharp/System/Exception/.ctor/getobjdata.cs

Lines changed: 120 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -3,128 +3,126 @@
33
using System.IO;
44
using System.Runtime.Serialization;
55
using System.Runtime.Serialization.Formatters.Soap;
6-
using System.Security.Permissions;
7-
8-
// Define a serializable derived exception class.
9-
[Serializable()]
10-
class SecondLevelException : Exception, ISerializable
11-
{
12-
// This public constructor is used by class instantiators.
13-
public SecondLevelException( string message, Exception inner ) :
14-
base( message, inner )
15-
{
16-
HelpLink = "http://MSDN.Microsoft.com";
17-
Source = "Exception_Class_Samples";
18-
}
19-
20-
// This protected constructor is used for deserialization.
21-
protected SecondLevelException( SerializationInfo info,
22-
StreamingContext context ) :
23-
base( info, context )
24-
{ }
25-
26-
// GetObjectData performs a custom serialization.
27-
[SecurityPermissionAttribute(SecurityAction.Demand,SerializationFormatter=true)]
28-
public override void GetObjectData( SerializationInfo info,
29-
StreamingContext context )
30-
{
31-
// Change the case of two properties, and then use the
32-
// method of the base class.
33-
HelpLink = HelpLink.ToLower( );
34-
Source = Source.ToUpperInvariant();
35-
36-
base.GetObjectData( info, context );
37-
}
38-
}
39-
40-
class SerializationDemo
41-
{
42-
public static void Main()
43-
{
44-
Console.WriteLine(
45-
"This example of the Exception constructor " +
46-
"and Exception.GetObjectData\nwith Serialization" +
47-
"Info and StreamingContext parameters " +
48-
"generates \nthe following output.\n" );
49-
50-
try
51-
{
52-
// This code forces a division by 0 and catches the
53-
// resulting exception.
54-
try
55-
{
56-
int zero = 0;
57-
int ecks = 1 / zero;
58-
}
59-
catch( Exception ex )
60-
{
61-
// Create a new exception to throw again.
62-
SecondLevelException newExcept =
63-
new SecondLevelException(
64-
"Forced a division by 0 and threw " +
65-
"another exception.", ex );
66-
67-
Console.WriteLine(
68-
"Forced a division by 0, caught the " +
69-
"resulting exception, \n" +
70-
"and created a derived exception:\n" );
71-
Console.WriteLine( "HelpLink: {0}",
72-
newExcept.HelpLink );
73-
Console.WriteLine( "Source: {0}",
74-
newExcept.Source );
75-
76-
// This FileStream is used for the serialization.
77-
FileStream stream =
78-
new FileStream( "NewException.dat",
79-
FileMode.Create );
80-
81-
try
82-
{
83-
// Serialize the derived exception.
84-
SoapFormatter formatter =
85-
new SoapFormatter( null,
86-
new StreamingContext(
87-
StreamingContextStates.File ) );
88-
formatter.Serialize( stream, newExcept );
89-
90-
// Rewind the stream and deserialize the
91-
// exception.
92-
stream.Position = 0;
93-
SecondLevelException deserExcept =
94-
(SecondLevelException)
95-
formatter.Deserialize( stream );
96-
97-
Console.WriteLine(
98-
"\nSerialized the exception, and then " +
99-
"deserialized the resulting stream " +
100-
"into a \nnew exception. " +
101-
"The deserialization changed the case " +
102-
"of certain properties:\n" );
103-
104-
// Throw the deserialized exception again.
105-
throw deserExcept;
106-
}
107-
catch( SerializationException se )
108-
{
109-
Console.WriteLine( "Failed to serialize: {0}",
110-
se.ToString( ) );
111-
}
112-
finally
113-
{
114-
stream.Close( );
115-
}
116-
}
117-
}
118-
catch( Exception ex )
119-
{
120-
Console.WriteLine( "HelpLink: {0}", ex.HelpLink );
121-
Console.WriteLine( "Source: {0}", ex.Source );
122-
123-
Console.WriteLine( );
124-
Console.WriteLine( ex.ToString( ) );
125-
}
126-
}
127-
}
6+
7+
// Define a serializable derived exception class.
8+
[Serializable()]
9+
class SecondLevelException : Exception, ISerializable
10+
{
11+
// This public constructor is used by class instantiators.
12+
public SecondLevelException(string message, Exception inner) :
13+
base(message, inner)
14+
{
15+
HelpLink = "http://MSDN.Microsoft.com";
16+
Source = "Exception_Class_Samples";
17+
}
18+
19+
// This protected constructor is used for deserialization.
20+
protected SecondLevelException(SerializationInfo info,
21+
StreamingContext context) :
22+
base(info, context)
23+
{ }
24+
25+
// GetObjectData performs a custom serialization.
26+
public override void GetObjectData(SerializationInfo info,
27+
StreamingContext context)
28+
{
29+
// Change the case of two properties, and then use the
30+
// method of the base class.
31+
HelpLink = HelpLink.ToLower();
32+
Source = Source.ToUpperInvariant();
33+
34+
base.GetObjectData(info, context);
35+
}
36+
}
37+
38+
class SerializationDemo
39+
{
40+
public static void Main()
41+
{
42+
Console.WriteLine(
43+
"This example of the Exception constructor " +
44+
"and Exception.GetObjectData\nwith Serialization" +
45+
"Info and StreamingContext parameters " +
46+
"generates \nthe following output.\n");
47+
48+
try
49+
{
50+
// This code forces a division by 0 and catches the
51+
// resulting exception.
52+
try
53+
{
54+
int zero = 0;
55+
int ecks = 1 / zero;
56+
}
57+
catch (Exception ex)
58+
{
59+
// Create a new exception to throw again.
60+
SecondLevelException newExcept =
61+
new SecondLevelException(
62+
"Forced a division by 0 and threw " +
63+
"another exception.", ex);
64+
65+
Console.WriteLine(
66+
"Forced a division by 0, caught the " +
67+
"resulting exception, \n" +
68+
"and created a derived exception:\n");
69+
Console.WriteLine("HelpLink: {0}",
70+
newExcept.HelpLink);
71+
Console.WriteLine("Source: {0}",
72+
newExcept.Source);
73+
74+
// This FileStream is used for the serialization.
75+
FileStream stream =
76+
new FileStream("NewException.dat",
77+
FileMode.Create);
78+
79+
try
80+
{
81+
// Serialize the derived exception.
82+
SoapFormatter formatter =
83+
new SoapFormatter(null,
84+
new StreamingContext(
85+
StreamingContextStates.File));
86+
formatter.Serialize(stream, newExcept);
87+
88+
// Rewind the stream and deserialize the
89+
// exception.
90+
stream.Position = 0;
91+
SecondLevelException deserExcept =
92+
(SecondLevelException)
93+
formatter.Deserialize(stream);
94+
95+
Console.WriteLine(
96+
"\nSerialized the exception, and then " +
97+
"deserialized the resulting stream " +
98+
"into a \nnew exception. " +
99+
"The deserialization changed the case " +
100+
"of certain properties:\n");
101+
102+
// Throw the deserialized exception again.
103+
throw deserExcept;
104+
}
105+
catch (SerializationException se)
106+
{
107+
Console.WriteLine("Failed to serialize: {0}",
108+
se.ToString());
109+
}
110+
finally
111+
{
112+
stream.Close();
113+
}
114+
}
115+
}
116+
catch (Exception ex)
117+
{
118+
Console.WriteLine("HelpLink: {0}", ex.HelpLink);
119+
Console.WriteLine("Source: {0}", ex.Source);
120+
121+
Console.WriteLine();
122+
Console.WriteLine(ex.ToString());
123+
}
124+
}
125+
}
128126
/*
129127
This example displays the following output.
130128

snippets/csharp/System/Exception/.ctor/news.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Example for the Exception( string ) constructor.
33
using System;
44

5-
namespace NDP_UE_CS
5+
namespace NDP_UE_CS2
66
{
77
// Derive an exception with a specifiable message.
88
class NotEvenException : Exception

0 commit comments

Comments
 (0)