Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>net4.8</TargetFrameworks>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
//<Snippet1>
using System;
using System.Collections;
using System.Text;
using System.Security.Policy;
using System.Reflection;
using System.Security;
using System.Security.Permissions;

namespace ActivationContextSample
{
public class Program : MarshalByRefObject
{
[SecurityPermission(SecurityAction.LinkDemand, ControlDomainPolicy=true)]
public static void Main(string[] args)
{
//<Snippet3>
Expand All @@ -25,7 +18,7 @@ public static void Main(string[] args)

Console.Read();
}
[SecurityPermission(SecurityAction.LinkDemand, ControlDomainPolicy=true)]

public void Run()
{
Main(new string[] { });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// <Snippet1>
using System;
using System.Security.Permissions;

public class Example
{
[SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlAppDomain)]
public static void Main()
{
AppDomain currentDomain = AppDomain.CurrentDomain;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>net4.8</TargetFrameworks>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using System.Net;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Security.Policy;
using System.Security.Principal;
using System.Threading;
Expand All @@ -22,10 +21,6 @@
namespace MyNamespace
{
[GuidAttribute("F4D15099-3407-4A7E-A607-DEA440CF3891")]
[SecurityPermissionAttribute(SecurityAction.LinkDemand,
Flags = SecurityPermissionFlag.Infrastructure)]
[SecurityPermissionAttribute(SecurityAction.InheritanceDemand,
Flags = SecurityPermissionFlag.Infrastructure)]
public class MyAppDomainManager : AppDomainManager
{
private HostSecurityManager mySecurityManager = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>net4.8</TargetFrameworks>
</PropertyGroup>
</Project>
4 changes: 1 addition & 3 deletions snippets/csharp/System/ApplicationId/Overview/program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
using System.Security.Policy;
using System.Reflection;
using System.Security;
using System.Security.Permissions;

namespace ActivationContextSample
{
public class Program : MarshalByRefObject
{
[SecurityPermission(SecurityAction.Demand, ControlDomainPolicy = true)]
public static void Main(string[] args)
{
//<Snippet2>
Expand Down Expand Up @@ -57,4 +55,4 @@ public void Run()
}
}
}
//</Snippet1>
//</Snippet1>
9 changes: 9 additions & 0 deletions snippets/csharp/System/Exception/.ctor/Project.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>net4.8</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.Runtime.Serialization.Formatters.Soap" />
</ItemGroup>
</Project>
242 changes: 120 additions & 122 deletions snippets/csharp/System/Exception/.ctor/getobjdata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,128 +3,126 @@
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Soap;
using System.Security.Permissions;

// Define a serializable derived exception class.
[Serializable()]
class SecondLevelException : Exception, ISerializable
{
// This public constructor is used by class instantiators.
public SecondLevelException( string message, Exception inner ) :
base( message, inner )
{
HelpLink = "http://MSDN.Microsoft.com";
Source = "Exception_Class_Samples";
}

// This protected constructor is used for deserialization.
protected SecondLevelException( SerializationInfo info,
StreamingContext context ) :
base( info, context )
{ }

// GetObjectData performs a custom serialization.
[SecurityPermissionAttribute(SecurityAction.Demand,SerializationFormatter=true)]
public override void GetObjectData( SerializationInfo info,
StreamingContext context )
{
// Change the case of two properties, and then use the
// method of the base class.
HelpLink = HelpLink.ToLower( );
Source = Source.ToUpperInvariant();

base.GetObjectData( info, context );
}
}

class SerializationDemo
{
public static void Main()
{
Console.WriteLine(
"This example of the Exception constructor " +
"and Exception.GetObjectData\nwith Serialization" +
"Info and StreamingContext parameters " +
"generates \nthe following output.\n" );

try
{
// This code forces a division by 0 and catches the
// resulting exception.
try
{
int zero = 0;
int ecks = 1 / zero;
}
catch( Exception ex )
{
// Create a new exception to throw again.
SecondLevelException newExcept =
new SecondLevelException(
"Forced a division by 0 and threw " +
"another exception.", ex );

Console.WriteLine(
"Forced a division by 0, caught the " +
"resulting exception, \n" +
"and created a derived exception:\n" );
Console.WriteLine( "HelpLink: {0}",
newExcept.HelpLink );
Console.WriteLine( "Source: {0}",
newExcept.Source );

// This FileStream is used for the serialization.
FileStream stream =
new FileStream( "NewException.dat",
FileMode.Create );

try
{
// Serialize the derived exception.
SoapFormatter formatter =
new SoapFormatter( null,
new StreamingContext(
StreamingContextStates.File ) );
formatter.Serialize( stream, newExcept );

// Rewind the stream and deserialize the
// exception.
stream.Position = 0;
SecondLevelException deserExcept =
(SecondLevelException)
formatter.Deserialize( stream );

Console.WriteLine(
"\nSerialized the exception, and then " +
"deserialized the resulting stream " +
"into a \nnew exception. " +
"The deserialization changed the case " +
"of certain properties:\n" );

// Throw the deserialized exception again.
throw deserExcept;
}
catch( SerializationException se )
{
Console.WriteLine( "Failed to serialize: {0}",
se.ToString( ) );
}
finally
{
stream.Close( );
}
}
}
catch( Exception ex )
{
Console.WriteLine( "HelpLink: {0}", ex.HelpLink );
Console.WriteLine( "Source: {0}", ex.Source );

Console.WriteLine( );
Console.WriteLine( ex.ToString( ) );
}
}
}

// Define a serializable derived exception class.
[Serializable()]
class SecondLevelException : Exception, ISerializable
{
// This public constructor is used by class instantiators.
public SecondLevelException(string message, Exception inner) :
base(message, inner)
{
HelpLink = "http://MSDN.Microsoft.com";
Source = "Exception_Class_Samples";
}

// This protected constructor is used for deserialization.
protected SecondLevelException(SerializationInfo info,
StreamingContext context) :
base(info, context)
{ }

// GetObjectData performs a custom serialization.
public override void GetObjectData(SerializationInfo info,
StreamingContext context)
{
// Change the case of two properties, and then use the
// method of the base class.
HelpLink = HelpLink.ToLower();
Source = Source.ToUpperInvariant();

base.GetObjectData(info, context);
}
}

class SerializationDemo
{
public static void Main()
{
Console.WriteLine(
"This example of the Exception constructor " +
"and Exception.GetObjectData\nwith Serialization" +
"Info and StreamingContext parameters " +
"generates \nthe following output.\n");

try
{
// This code forces a division by 0 and catches the
// resulting exception.
try
{
int zero = 0;
int ecks = 1 / zero;
}
catch (Exception ex)
{
// Create a new exception to throw again.
SecondLevelException newExcept =
new SecondLevelException(
"Forced a division by 0 and threw " +
"another exception.", ex);

Console.WriteLine(
"Forced a division by 0, caught the " +
"resulting exception, \n" +
"and created a derived exception:\n");
Console.WriteLine("HelpLink: {0}",
newExcept.HelpLink);
Console.WriteLine("Source: {0}",
newExcept.Source);

// This FileStream is used for the serialization.
FileStream stream =
new FileStream("NewException.dat",
FileMode.Create);

try
{
// Serialize the derived exception.
SoapFormatter formatter =
new SoapFormatter(null,
new StreamingContext(
StreamingContextStates.File));
formatter.Serialize(stream, newExcept);

// Rewind the stream and deserialize the
// exception.
stream.Position = 0;
SecondLevelException deserExcept =
(SecondLevelException)
formatter.Deserialize(stream);

Console.WriteLine(
"\nSerialized the exception, and then " +
"deserialized the resulting stream " +
"into a \nnew exception. " +
"The deserialization changed the case " +
"of certain properties:\n");

// Throw the deserialized exception again.
throw deserExcept;
}
catch (SerializationException se)
{
Console.WriteLine("Failed to serialize: {0}",
se.ToString());
}
finally
{
stream.Close();
}
}
}
catch (Exception ex)
{
Console.WriteLine("HelpLink: {0}", ex.HelpLink);
Console.WriteLine("Source: {0}", ex.Source);

Console.WriteLine();
Console.WriteLine(ex.ToString());
}
}
}
/*
This example displays the following output.

Expand Down
2 changes: 1 addition & 1 deletion snippets/csharp/System/Exception/.ctor/news.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Example for the Exception( string ) constructor.
using System;

namespace NDP_UE_CS
namespace NDP_UE_CS2
{
// Derive an exception with a specifiable message.
class NotEvenException : Exception
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>net4.8</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.Runtime.Serialization.Formatters.Soap" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using System;
using System.Runtime.Remoting.Lifetime;
using System.Security.Permissions;

// <Snippet1>
public class MyClass : MarshalByRefObject
{
[SecurityPermissionAttribute(SecurityAction.Demand,
Flags=SecurityPermissionFlag.Infrastructure)]
public override Object InitializeLifetimeService()
{
ILease lease = (ILease)base.InitializeLifetimeService();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>net4.8</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.Runtime.Serialization.Formatters.Soap" />
</ItemGroup>
</Project>
Loading