From 3746dc016fe93278491bd4cbf3acb17ad5a59158 Mon Sep 17 00:00:00 2001
From: albert-du <52804499+albert-du@users.noreply.github.com>
Date: Sun, 3 Apr 2022 10:38:42 -0700
Subject: [PATCH] AppDomain F# snippets
---
.../AppDomain/AssemblyLoad/assemblyload.fs | 27 +++
.../System/AppDomain/AssemblyLoad/fs.fsproj | 10 ++
.../AssemblyResolve/assemblyresolve.fs | 48 ++++++
.../AppDomain/AssemblyResolve/fs.fsproj | 10 ++
.../System/AppDomain/BaseDirectory/adsetup.fs | 29 ++++
.../System/AppDomain/BaseDirectory/fs.fsproj | 10 ++
.../ClearPrivatePath/adclearprivatepath.fs | 27 +++
.../AppDomain/ClearPrivatePath/fs.fsproj | 10 ++
.../createcominstancefrom.fs | 27 +++
.../AppDomain/CreateComInstanceFrom/fs.fsproj | 10 ++
.../System/AppDomain/CreateDomain/fs.fsproj | 10 ++
.../System/AppDomain/CreateDomain/setup.fs | 18 ++
.../CreateInstanceAndUnwrap/addyno.fs | 156 ++++++++++++++++++
.../CreateInstanceAndUnwrap/fs.fsproj | 4 +-
.../CreateInstanceAndUnwrap/ignorecase.fs | 27 +++
.../CreateInstanceAndUnwrap/source.fs | 4 +-
.../AppDomain/CreateInstanceFrom/example.fs | 48 ++++++
.../AppDomain/CreateInstanceFrom/fs.fsproj | 10 ++
.../CurrentDomain/adapplicationbase.fs | 24 +++
.../System/AppDomain/CurrentDomain/fs.fsproj | 10 ++
.../definedynamicassembly.fs | 46 ++++++
.../AppDomain/DefineDynamicAssembly/fs.fsproj | 11 ++
.../AppDomain/DefineDynamicAssembly/source.fs | 45 +++++
.../AppDomain/DoCallBack/docallback_byref.fs | 29 ++++
.../AppDomain/DoCallBack/docallback_byval.fs | 30 ++++
.../AppDomain/DoCallBack/docallback_static.fs | 23 +++
.../System/AppDomain/DoCallBack/fs.fsproj | 12 ++
.../DynamicDirectory/addynamicbase.fs | 92 +++++++++++
.../AppDomain/DynamicDirectory/fs.fsproj | 10 ++
.../ExecuteAssembly/executeassembly.fs | 14 ++
.../AppDomain/ExecuteAssembly/fs.fsproj | 10 ++
.../AppDomain/FirstChanceException/example.fs | 75 +++++++++
.../AppDomain/FirstChanceException/fs.fsproj | 10 ++
.../GetAssemblies/adgetassemblies.fs | 19 +++
.../System/AppDomain/GetAssemblies/fs.fsproj | 10 ++
.../System/AppDomain/GetData/adgetdata.fs | 23 +++
.../fsharp/System/AppDomain/GetData/fs.fsproj | 10 ++
snippets/fsharp/System/AppDomain/Id/fs.fsproj | 10 ++
snippets/fsharp/System/AppDomain/Id/source.fs | 25 +++
.../AppDomain/IsFullyTrusted/example.fs | 48 ++++++
.../System/AppDomain/IsFullyTrusted/fs.fsproj | 10 ++
.../fsharp/System/AppDomain/Load/fs.fsproj | 11 ++
.../fsharp/System/AppDomain/Load/loadraw.fs | 62 +++++++
.../fsharp/System/AppDomain/Load/source.fs | 6 +
.../System/AppDomain/Overview/AppDomainX.fs | 78 +++++++++
.../System/AppDomain/Overview/fs.fsproj | 10 ++
.../ReflectionOnlyGetAssemblies/fs.fsproj | 10 ++
.../reflectiononly.fs | 27 +++
.../adsetappdomainpolicy.fs | 32 ++++
.../AppDomain/SetAppDomainPolicy/fs.fsproj | 10 ++
.../SetPrincipalPolicy/adprincipal.fs | 44 +++++
.../AppDomain/SetPrincipalPolicy/fs.fsproj | 10 ++
.../SetShadowCopyFiles/adproperties.fs | 52 ++++++
.../AppDomain/SetShadowCopyFiles/fs.fsproj | 10 ++
.../SetShadowCopyPath/adshadowcopy.fs | 51 ++++++
.../AppDomain/SetShadowCopyPath/fs.fsproj | 10 ++
.../System/AppDomain/ToString/adtostring.fs | 19 +++
.../System/AppDomain/ToString/fs.fsproj | 10 ++
.../System/AppDomain/TypeResolve/fs.fsproj | 10 ++
.../AppDomain/TypeResolve/typeresolve.fs | 58 +++++++
.../AppDomain/UnhandledException/fs.fsproj | 10 ++
.../UnhandledException/unhandledexception.fs | 30 ++++
.../System/AppDomain/Unload/adunload.fs | 22 +++
.../fsharp/System/AppDomain/Unload/fs.fsproj | 10 ++
.../AppDomainInitializer/fs.fsproj | 10 ++
.../AppDomainInitializer/source.fs | 49 ++++++
.../ApplicationName/admultidomain.fs | 37 +++++
.../AppDomainSetup/ApplicationName/fs.fsproj | 10 ++
.../Overview/Sample.fs | 71 ++++++++
.../Overview/fs.fsproj | 10 ++
xml/System/AppDomain.xml | 59 +++++++
xml/System/AppDomainSetup.xml | 6 +
xml/System/AppDomainUnloadedException.xml | 2 +
73 files changed, 1925 insertions(+), 2 deletions(-)
create mode 100644 snippets/fsharp/System/AppDomain/AssemblyLoad/assemblyload.fs
create mode 100644 snippets/fsharp/System/AppDomain/AssemblyLoad/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/AssemblyResolve/assemblyresolve.fs
create mode 100644 snippets/fsharp/System/AppDomain/AssemblyResolve/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/BaseDirectory/adsetup.fs
create mode 100644 snippets/fsharp/System/AppDomain/BaseDirectory/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/ClearPrivatePath/adclearprivatepath.fs
create mode 100644 snippets/fsharp/System/AppDomain/ClearPrivatePath/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/CreateComInstanceFrom/createcominstancefrom.fs
create mode 100644 snippets/fsharp/System/AppDomain/CreateComInstanceFrom/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/CreateDomain/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/CreateDomain/setup.fs
create mode 100644 snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/addyno.fs
create mode 100644 snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/ignorecase.fs
create mode 100644 snippets/fsharp/System/AppDomain/CreateInstanceFrom/example.fs
create mode 100644 snippets/fsharp/System/AppDomain/CreateInstanceFrom/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/CurrentDomain/adapplicationbase.fs
create mode 100644 snippets/fsharp/System/AppDomain/CurrentDomain/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/DefineDynamicAssembly/definedynamicassembly.fs
create mode 100644 snippets/fsharp/System/AppDomain/DefineDynamicAssembly/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/DefineDynamicAssembly/source.fs
create mode 100644 snippets/fsharp/System/AppDomain/DoCallBack/docallback_byref.fs
create mode 100644 snippets/fsharp/System/AppDomain/DoCallBack/docallback_byval.fs
create mode 100644 snippets/fsharp/System/AppDomain/DoCallBack/docallback_static.fs
create mode 100644 snippets/fsharp/System/AppDomain/DoCallBack/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/DynamicDirectory/addynamicbase.fs
create mode 100644 snippets/fsharp/System/AppDomain/DynamicDirectory/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/ExecuteAssembly/executeassembly.fs
create mode 100644 snippets/fsharp/System/AppDomain/ExecuteAssembly/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/FirstChanceException/example.fs
create mode 100644 snippets/fsharp/System/AppDomain/FirstChanceException/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/GetAssemblies/adgetassemblies.fs
create mode 100644 snippets/fsharp/System/AppDomain/GetAssemblies/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/GetData/adgetdata.fs
create mode 100644 snippets/fsharp/System/AppDomain/GetData/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/Id/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/Id/source.fs
create mode 100644 snippets/fsharp/System/AppDomain/IsFullyTrusted/example.fs
create mode 100644 snippets/fsharp/System/AppDomain/IsFullyTrusted/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/Load/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/Load/loadraw.fs
create mode 100644 snippets/fsharp/System/AppDomain/Load/source.fs
create mode 100644 snippets/fsharp/System/AppDomain/Overview/AppDomainX.fs
create mode 100644 snippets/fsharp/System/AppDomain/Overview/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/ReflectionOnlyGetAssemblies/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/ReflectionOnlyGetAssemblies/reflectiononly.fs
create mode 100644 snippets/fsharp/System/AppDomain/SetAppDomainPolicy/adsetappdomainpolicy.fs
create mode 100644 snippets/fsharp/System/AppDomain/SetAppDomainPolicy/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/SetPrincipalPolicy/adprincipal.fs
create mode 100644 snippets/fsharp/System/AppDomain/SetPrincipalPolicy/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/SetShadowCopyFiles/adproperties.fs
create mode 100644 snippets/fsharp/System/AppDomain/SetShadowCopyFiles/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/SetShadowCopyPath/adshadowcopy.fs
create mode 100644 snippets/fsharp/System/AppDomain/SetShadowCopyPath/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/ToString/adtostring.fs
create mode 100644 snippets/fsharp/System/AppDomain/ToString/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/TypeResolve/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/TypeResolve/typeresolve.fs
create mode 100644 snippets/fsharp/System/AppDomain/UnhandledException/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomain/UnhandledException/unhandledexception.fs
create mode 100644 snippets/fsharp/System/AppDomain/Unload/adunload.fs
create mode 100644 snippets/fsharp/System/AppDomain/Unload/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomainSetup/AppDomainInitializer/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomainSetup/AppDomainInitializer/source.fs
create mode 100644 snippets/fsharp/System/AppDomainSetup/ApplicationName/admultidomain.fs
create mode 100644 snippets/fsharp/System/AppDomainSetup/ApplicationName/fs.fsproj
create mode 100644 snippets/fsharp/System/AppDomainUnloadedException/Overview/Sample.fs
create mode 100644 snippets/fsharp/System/AppDomainUnloadedException/Overview/fs.fsproj
diff --git a/snippets/fsharp/System/AppDomain/AssemblyLoad/assemblyload.fs b/snippets/fsharp/System/AppDomain/AssemblyLoad/assemblyload.fs
new file mode 100644
index 00000000000..5ddd37e97b0
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/AssemblyLoad/assemblyload.fs
@@ -0,0 +1,27 @@
+//
+open System
+
+let printLoadedAssemblies (domain: AppDomain) =
+ printfn "LOADED ASSEMBLIES:"
+ for a in domain.GetAssemblies() do
+ printfn $"{a.FullName}"
+ printfn ""
+
+let myAssemblyLoadEventHandler _ (args: AssemblyLoadEventArgs) =
+ printfn $"ASSEMBLY LOADED: {args.LoadedAssembly.FullName}\n"
+
+let currentDomain = AppDomain.CurrentDomain
+currentDomain.AssemblyLoad.AddHandler(AssemblyLoadEventHandler myAssemblyLoadEventHandler)
+
+printLoadedAssemblies currentDomain
+// Lists mscorlib and this assembly
+
+// You must supply a valid fully qualified assembly name here.
+currentDomain.CreateInstance("System.Windows.Forms, Version, Culture, PublicKeyToken", "System.Windows.Forms.TextBox")
+// Loads System, System.Drawing, System.Windows.Forms
+
+printLoadedAssemblies currentDomain
+// Lists all five assemblies
+
+
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/AssemblyLoad/fs.fsproj b/snippets/fsharp/System/AppDomain/AssemblyLoad/fs.fsproj
new file mode 100644
index 00000000000..54a9b8b65f1
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/AssemblyLoad/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/AssemblyResolve/assemblyresolve.fs b/snippets/fsharp/System/AppDomain/AssemblyResolve/assemblyresolve.fs
new file mode 100644
index 00000000000..d584c8fe2ef
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/AssemblyResolve/assemblyresolve.fs
@@ -0,0 +1,48 @@
+open System
+open System.Reflection
+
+//
+type MyType() =
+ do
+ printfn "\nMyType instantiated!"
+
+let instantiateMyTypeFail (domain: AppDomain) =
+ // Calling InstantiateMyType will always fail since the assembly info
+ // given to CreateInstance is invalid.
+ try
+ // You must supply a valid fully qualified assembly name here.
+ domain.CreateInstance("Assembly text name, Version, Culture, PublicKeyToken", "MyType")
+ |> ignore
+ with e ->
+ printfn $"\n{e.Message}"
+
+let instantiateMyTypeSucceed (domain: AppDomain) =
+ try
+ let asmname = Assembly.GetCallingAssembly().FullName
+ domain.CreateInstance(asmname, "MyType")
+ |> ignore
+ with e ->
+ printfn $"\n{e.Message}"
+
+let myResolveEventHandler _ _ =
+ printfn "Resolving..."
+ typeof.Assembly
+
+
+let currentDomain = AppDomain.CurrentDomain
+
+// This call will fail to create an instance of MyType since the
+// assembly resolver is not set
+instantiateMyTypeFail currentDomain
+
+currentDomain.add_AssemblyResolve (ResolveEventHandler myResolveEventHandler)
+
+// This call will succeed in creating an instance of MyType since the
+// assembly resolver is now set.
+instantiateMyTypeFail currentDomain
+
+// This call will succeed in creating an instance of MyType since the
+// assembly name is valid.
+instantiateMyTypeSucceed currentDomain
+
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/AssemblyResolve/fs.fsproj b/snippets/fsharp/System/AppDomain/AssemblyResolve/fs.fsproj
new file mode 100644
index 00000000000..542fde5fd08
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/AssemblyResolve/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/BaseDirectory/adsetup.fs b/snippets/fsharp/System/AppDomain/BaseDirectory/adsetup.fs
new file mode 100644
index 00000000000..1be467cb2f0
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/BaseDirectory/adsetup.fs
@@ -0,0 +1,29 @@
+//
+open System
+open System.IO
+
+// Create application domain setup information
+let domaininfo = AppDomainSetup()
+domaininfo.ConfigurationFile <- Environment.CurrentDirectory + string Path.DirectorySeparatorChar + "ADSetup.exe.config"
+domaininfo.ApplicationBase <- Environment.CurrentDirectory
+
+//Create evidence for the new appdomain from evidence of the current application domain
+let adEvidence = AppDomain.CurrentDomain.Evidence
+
+// Create appdomain
+let domain = AppDomain.CreateDomain("Domain2", adEvidence, domaininfo)
+
+// Display application domain information.
+printfn $"Host domain: {AppDomain.CurrentDomain.FriendlyName}"
+printfn $"Child domain: {domain.FriendlyName}\n"
+printfn $"Configuration file: {domain.SetupInformation.ConfigurationFile}"
+printfn $"Application Base Directory: {domain.BaseDirectory}"
+
+AppDomain.Unload domain
+// The example displays output like the following:
+// Host domain: adsetup.exe
+// Child domain: Domain2
+//
+// Configuration file: C:\Test\ADSetup.exe.config
+// Application Base Directory: C:\Test
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/BaseDirectory/fs.fsproj b/snippets/fsharp/System/AppDomain/BaseDirectory/fs.fsproj
new file mode 100644
index 00000000000..bf55b7f18e6
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/BaseDirectory/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net48
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/ClearPrivatePath/adclearprivatepath.fs b/snippets/fsharp/System/AppDomain/ClearPrivatePath/adclearprivatepath.fs
new file mode 100644
index 00000000000..d78b8fd27e3
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/ClearPrivatePath/adclearprivatepath.fs
@@ -0,0 +1,27 @@
+//
+open System
+
+//Create evidence for new appdomain.
+let adevidence = AppDomain.CurrentDomain.Evidence
+
+//Create the new application domain.
+let domain = AppDomain.CreateDomain("MyDomain", adevidence)
+
+//Display the current relative search path.
+printfn $"Relative search path is: {domain.RelativeSearchPath}"
+
+//Append the relative path.
+let Newpath = "www.code.microsoft.com"
+domain.AppendPrivatePath Newpath
+
+//Display the new relative search path.
+printfn $"Relative search path is: {domain.RelativeSearchPath}"
+
+//Clear the private search path.
+domain.ClearPrivatePath()
+
+//Display the new relative search path.
+printfn $"Relative search path is now: {domain.RelativeSearchPath}"
+
+AppDomain.Unload domain
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/ClearPrivatePath/fs.fsproj b/snippets/fsharp/System/AppDomain/ClearPrivatePath/fs.fsproj
new file mode 100644
index 00000000000..79b3de7856f
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/ClearPrivatePath/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net48
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/CreateComInstanceFrom/createcominstancefrom.fs b/snippets/fsharp/System/AppDomain/CreateComInstanceFrom/createcominstancefrom.fs
new file mode 100644
index 00000000000..48035fe7066
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/CreateComInstanceFrom/createcominstancefrom.fs
@@ -0,0 +1,27 @@
+//
+open System
+open System.Runtime.InteropServices
+
+[]
+type MyComVisibleType() =
+ do
+ printfn "MyComVisibleType instantiated!"
+
+[]
+type MyComNonVisibleType() =
+ do
+ printfn "MyComNonVisibleType instantiated!"
+
+let createComInstance typeName =
+ try
+ let currentDomain = AppDomain.CurrentDomain
+ let assemblyName = currentDomain.FriendlyName
+ currentDomain.CreateComInstanceFrom(assemblyName, typeName)
+ |> ignore
+ with e ->
+ printfn $"{e.Message}"
+
+createComInstance "MyComNonVisibleType" // Fail!
+createComInstance "MyComVisibleType" // OK!
+
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/CreateComInstanceFrom/fs.fsproj b/snippets/fsharp/System/AppDomain/CreateComInstanceFrom/fs.fsproj
new file mode 100644
index 00000000000..17f0c4a1761
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/CreateComInstanceFrom/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net48
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/CreateDomain/fs.fsproj b/snippets/fsharp/System/AppDomain/CreateDomain/fs.fsproj
new file mode 100644
index 00000000000..56d3d187e08
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/CreateDomain/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net48
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/CreateDomain/setup.fs b/snippets/fsharp/System/AppDomain/CreateDomain/setup.fs
new file mode 100644
index 00000000000..d23b5ed2dec
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/CreateDomain/setup.fs
@@ -0,0 +1,18 @@
+//
+open System
+open System.Security.Policy
+
+// Set up the AppDomainSetup
+let setup = AppDomainSetup()
+setup.ApplicationBase <- "(some directory)"
+setup.ConfigurationFile <- "(some file)"
+
+// Set up the Evidence
+let baseEvidence = AppDomain.CurrentDomain.Evidence
+let evidence = Evidence baseEvidence
+evidence.AddAssembly "(some assembly)"
+evidence.AddHost "(some host)"
+
+// Create the AppDomain
+let newDomain = AppDomain.CreateDomain("newDomain", evidence, setup)
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/addyno.fs b/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/addyno.fs
new file mode 100644
index 00000000000..01e1286ba26
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/addyno.fs
@@ -0,0 +1,156 @@
+module addyno
+
+//
+open System
+open System.IO
+open System.Threading
+open System.Reflection
+open System.Reflection.Emit
+
+let createADynamicAssembly (myNewDomain: byref) executableNameNoExe =
+ let executableName = executableNameNoExe + ".exe"
+
+ let myAsmName = AssemblyName()
+ myAsmName.Name <- executableNameNoExe
+ myAsmName.CodeBase <- Environment.CurrentDirectory
+
+ let myAsmBuilder =
+ myNewDomain.DefineDynamicAssembly(myAsmName, AssemblyBuilderAccess.RunAndSave)
+ printfn "-- Dynamic Assembly instantiated."
+
+ let myModBuilder =
+ myAsmBuilder.DefineDynamicModule(executableNameNoExe, executableName)
+
+ let myTypeBuilder =
+ myModBuilder.DefineType(executableNameNoExe,
+ TypeAttributes.Public,
+ typeof)
+
+ let myFCMethod =
+ myTypeBuilder.DefineMethod("CountLocalFiles",
+ MethodAttributes.Public |||
+ MethodAttributes.Static,
+ null,
+ [||])
+
+ let currentDirGetMI = typeof.GetProperty("CurrentDirectory").GetGetMethod()
+ let writeLine0objMI = typeof.GetMethod("WriteLine", [| typeof |])
+ let writeLine2objMI = typeof.GetMethod("WriteLine", [| typeof; typeof; typeof |])
+ let getFilesMI = typeof.GetMethod("GetFiles", [| typeof |])
+
+ myFCMethod.InitLocals <- true
+
+ let myFCIL = myFCMethod.GetILGenerator()
+
+ printfn "-- Generating MSIL method body..."
+ let v0 = myFCIL.DeclareLocal typeof
+ let v1 = myFCIL.DeclareLocal typeof
+ let v2 = myFCIL.DeclareLocal typeof
+ let v3 = myFCIL.DeclareLocal typeof
+
+ let evalForEachLabel = myFCIL.DefineLabel()
+ let topOfForEachLabel = myFCIL.DefineLabel()
+
+ // Build the method body.
+
+ myFCIL.EmitCall(OpCodes.Call, currentDirGetMI, null)
+ myFCIL.Emit(OpCodes.Stloc_S, v0)
+ myFCIL.Emit(OpCodes.Ldc_I4_0)
+ myFCIL.Emit(OpCodes.Stloc_S, v1)
+ myFCIL.Emit(OpCodes.Ldstr, "---")
+ myFCIL.EmitCall(OpCodes.Call, writeLine0objMI, null)
+ myFCIL.Emit(OpCodes.Ldloc_S, v0)
+ myFCIL.EmitCall(OpCodes.Call, getFilesMI, null)
+ myFCIL.Emit(OpCodes.Stloc_S, v3)
+
+ myFCIL.Emit(OpCodes.Br_S, evalForEachLabel)
+
+ // foreach loop starts here.
+ myFCIL.MarkLabel topOfForEachLabel
+
+ // Load array of strings and index, store value at index for output.
+ myFCIL.Emit(OpCodes.Ldloc_S, v3)
+ myFCIL.Emit(OpCodes.Ldloc_S, v1)
+ myFCIL.Emit OpCodes.Ldelem_Ref
+ myFCIL.Emit(OpCodes.Stloc_S, v2)
+
+ myFCIL.Emit(OpCodes.Ldloc_S, v2)
+ myFCIL.EmitCall(OpCodes.Call, writeLine0objMI, null)
+
+ // Increment counter by one.
+ myFCIL.Emit(OpCodes.Ldloc_S, v1)
+ myFCIL.Emit(OpCodes.Ldc_I4_1)
+ myFCIL.Emit OpCodes.Add
+ myFCIL.Emit(OpCodes.Stloc_S, v1)
+
+ // Determine if end of file list array has been reached.
+ myFCIL.MarkLabel evalForEachLabel
+ myFCIL.Emit(OpCodes.Ldloc_S, v1)
+ myFCIL.Emit(OpCodes.Ldloc_S, v3)
+ myFCIL.Emit OpCodes.Ldlen
+ myFCIL.Emit OpCodes.Conv_I4
+ myFCIL.Emit(OpCodes.Blt_S, topOfForEachLabel)
+ //foreach loop end here.
+
+ myFCIL.Emit(OpCodes.Ldstr, "---")
+ myFCIL.EmitCall(OpCodes.Call, writeLine0objMI, null)
+ myFCIL.Emit(OpCodes.Ldstr, "There are {0} files in {1}.")
+ myFCIL.Emit(OpCodes.Ldloc_S, v1)
+ myFCIL.Emit(OpCodes.Box, typeof)
+ myFCIL.Emit(OpCodes.Ldloc_S, v0)
+ myFCIL.EmitCall(OpCodes.Call, writeLine2objMI, null)
+
+ myFCIL.Emit OpCodes.Ret
+
+ let myType = myTypeBuilder.CreateType()
+
+ myAsmBuilder.SetEntryPoint myFCMethod
+ myAsmBuilder.Save executableName
+ printfn "-- Method generated, type completed, and assembly saved to disk."
+
+ myType
+
+
+printf "Enter a name for the file counting assembly: "
+let executableNameNoExe = stdin.ReadLine()
+let executableName = executableNameNoExe + ".exe"
+printfn "---"
+
+let domainDir = Environment.CurrentDirectory
+
+let mutable curDomain = Thread.GetDomain()
+
+// Create a new AppDomain, with the current directory as the base.
+
+printfn $"Current Directory: {Environment.CurrentDirectory}"
+let mySetupInfo = AppDomainSetup()
+mySetupInfo.ApplicationBase <- domainDir
+mySetupInfo.ApplicationName <- executableNameNoExe
+mySetupInfo.LoaderOptimization <- LoaderOptimization.SingleDomain
+
+let myDomain =
+ AppDomain.CreateDomain(executableNameNoExe, null, mySetupInfo)
+
+printfn $"Creating a new AppDomain '{executableNameNoExe}'..."
+
+printfn $"-- Base Directory = '{myDomain.BaseDirectory}'"
+printfn $"-- Shadow Copy? = '{myDomain.ShadowCopyFiles}'"
+
+printfn "---"
+let myFCType =
+ createADynamicAssembly &curDomain executableNameNoExe
+
+printfn $"Loading '{executableName}' from '{myDomain.BaseDirectory}'..."
+
+let bFlags =
+ BindingFlags.Public ||| BindingFlags.CreateInstance ||| BindingFlags.Instance
+
+let myObjInstance =
+ myDomain.CreateInstanceAndUnwrap(executableNameNoExe,
+ executableNameNoExe, false, bFlags,
+ null, null, null, null, null)
+
+printfn $"Executing method 'CountLocalFiles' in {myObjInstance}..."
+
+myFCType.InvokeMember("CountLocalFiles", BindingFlags.InvokeMethod, null, myObjInstance, [||])
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/fs.fsproj b/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/fs.fsproj
index f0a89cd967d..273b31df9f0 100644
--- a/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/fs.fsproj
+++ b/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/fs.fsproj
@@ -1,10 +1,12 @@
Exe
- net6.0
+ net48
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/ignorecase.fs b/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/ignorecase.fs
new file mode 100644
index 00000000000..b4b416d2e95
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/ignorecase.fs
@@ -0,0 +1,27 @@
+module ignorecase
+
+//
+open System
+open System.Reflection
+
+
+let instantiateINT32 ignoreCase =
+ try
+ let currentDomain = AppDomain.CurrentDomain
+ let instance = currentDomain.CreateInstanceAndUnwrap(
+ "mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
+ "SYSTEM.INT32",
+ ignoreCase,
+ BindingFlags.Default,
+ null,
+ null,
+ null,
+ null,
+ null)
+ printfn $"{instance.GetType()}"
+ with :? TypeLoadException as e ->
+ printfn $"{e.Message}"
+
+instantiateINT32 false // Failed!
+instantiateINT32 true // OK!
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/source.fs b/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/source.fs
index bab52102379..c7366f86b3e 100644
--- a/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/source.fs
+++ b/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/source.fs
@@ -1,4 +1,6 @@
-//
+module source
+
+//
open System
open System.Reflection
diff --git a/snippets/fsharp/System/AppDomain/CreateInstanceFrom/example.fs b/snippets/fsharp/System/AppDomain/CreateInstanceFrom/example.fs
new file mode 100644
index 00000000000..b434c8a0d28
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/CreateInstanceFrom/example.fs
@@ -0,0 +1,48 @@
+//
+open System
+
+type ITest =
+ abstract Test: string -> unit
+
+type MarshalableExample() =
+ inherit MarshalByRefObject()
+
+ member _.Test greeting =
+ printfn $"{greeting} from '{AppDomain.CurrentDomain.FriendlyName}'!"
+
+ interface ITest with
+ member this.Test message = this.Test message
+
+// Construct a path to the current assembly.
+let assemblyPath =
+ Environment.CurrentDirectory + "\\" + typeof.Assembly.GetName().Name + ".exe"
+
+let ad = AppDomain.CreateDomain "MyDomain"
+
+let oh =
+ ad.CreateInstanceFrom(assemblyPath, "MarshalableExample")
+
+let obj = oh.Unwrap()
+
+// Three ways to use the newly created object, depending on how
+// much is known about the type: Late bound, early bound through
+// a mutually known interface, or early binding of a known type.
+//
+obj.GetType().InvokeMember("Test",
+ System.Reflection.BindingFlags.InvokeMethod,
+ Type.DefaultBinder, obj, [| box "Hello" |])
+|> ignore
+
+let it = obj :?> ITest
+it.Test "Hi"
+
+let ex = obj :?> MarshalableExample
+ex.Test("Goodbye")
+
+(* This example produces the following output:
+
+Hello from 'MyDomain'!
+Hi from 'MyDomain'!
+Goodbye from 'MyDomain'!
+ *)
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/CreateInstanceFrom/fs.fsproj b/snippets/fsharp/System/AppDomain/CreateInstanceFrom/fs.fsproj
new file mode 100644
index 00000000000..2b336f60d41
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/CreateInstanceFrom/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/CurrentDomain/adapplicationbase.fs b/snippets/fsharp/System/AppDomain/CurrentDomain/adapplicationbase.fs
new file mode 100644
index 00000000000..5b6efde9c51
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/CurrentDomain/adapplicationbase.fs
@@ -0,0 +1,24 @@
+//
+open System
+
+let root = AppDomain.CurrentDomain
+
+let setup = AppDomainSetup()
+setup.ApplicationBase <-
+ root.SetupInformation.ApplicationBase + @"MyAppSubfolder\"
+
+let domain = AppDomain.CreateDomain("MyDomain", null, setup)
+
+printfn $"Application base of {root.FriendlyName}:\r\n\t{root.SetupInformation.ApplicationBase}"
+printfn $"Application base of {domain.FriendlyName}:\r\n\t{domain.SetupInformation.ApplicationBase}"
+
+AppDomain.Unload domain
+
+(* This example produces output similar to the following:
+
+Application base of MyApp.exe:
+ C:\Program Files\MyApp\
+Application base of MyDomain:
+ C:\Program Files\MyApp\MyAppSubfolder\
+ *)
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/CurrentDomain/fs.fsproj b/snippets/fsharp/System/AppDomain/CurrentDomain/fs.fsproj
new file mode 100644
index 00000000000..aff94bd0b7f
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/CurrentDomain/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net48
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/DefineDynamicAssembly/definedynamicassembly.fs b/snippets/fsharp/System/AppDomain/DefineDynamicAssembly/definedynamicassembly.fs
new file mode 100644
index 00000000000..ed99982def6
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/DefineDynamicAssembly/definedynamicassembly.fs
@@ -0,0 +1,46 @@
+module definedynamicassembly
+
+//
+open System
+open System.Reflection
+open System.Reflection.Emit
+
+let instantiateMyDynamicType (domain: AppDomain) =
+ try
+ // You must supply a valid fully qualified assembly name here.
+ domain.CreateInstance("Assembly text name, Version, Culture, PublicKeyToken", "MyDynamicType")
+ |> ignore
+ with e ->
+ printfn $"{e.Message}"
+
+let defineDynamicAssembly (domain: AppDomain) =
+ // Build a dynamic assembly using Reflection Emit API.
+ let assemblyName = AssemblyName()
+ assemblyName.Name <- "MyDynamicAssembly"
+
+ let assemblyBuilder = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run)
+ let moduleBuilder = assemblyBuilder.DefineDynamicModule "MyDynamicModule"
+ let typeBuilder = moduleBuilder.DefineType("MyDynamicType", TypeAttributes.Public)
+ let constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, null)
+ let ilGenerator = constructorBuilder.GetILGenerator()
+
+ ilGenerator.EmitWriteLine "MyDynamicType instantiated!"
+ ilGenerator.Emit OpCodes.Ret
+
+ typeBuilder.CreateType() |> ignore
+
+ assemblyBuilder
+
+let myResolveEventHandler (sender: obj) _ =
+ defineDynamicAssembly (sender :?> AppDomain)
+ :> Assembly
+
+let currentDomain = AppDomain.CurrentDomain
+
+instantiateMyDynamicType currentDomain // Failed!
+
+currentDomain.add_AssemblyResolve(ResolveEventHandler myResolveEventHandler)
+
+instantiateMyDynamicType currentDomain // OK!
+
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/DefineDynamicAssembly/fs.fsproj b/snippets/fsharp/System/AppDomain/DefineDynamicAssembly/fs.fsproj
new file mode 100644
index 00000000000..98d73295025
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/DefineDynamicAssembly/fs.fsproj
@@ -0,0 +1,11 @@
+
+
+ Exe
+ net48
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/DefineDynamicAssembly/source.fs b/snippets/fsharp/System/AppDomain/DefineDynamicAssembly/source.fs
new file mode 100644
index 00000000000..a11e36325a0
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/DefineDynamicAssembly/source.fs
@@ -0,0 +1,45 @@
+module source
+
+//
+open System
+open System.Reflection
+open System.Reflection.Emit
+open System.Security
+
+// Create a CustomAttributeBuilder for the assembly attribute.
+//
+// SecurityTransparentAttribute has a parameterless constructor,
+// which is retrieved by passing an array of empty types for the
+// constructor's parameter types. The CustomAttributeBuilder is
+// then created by passing the ConstructorInfo and an empty array
+// of objects to represent the parameters.
+//
+let transparentCtor =
+ typeof.GetConstructor(Type.EmptyTypes)
+let transparent = CustomAttributeBuilder(transparentCtor, [||])
+
+// Create a dynamic assembly using the attribute. The attribute is
+// passed as an array with one element.
+let aName = AssemblyName "EmittedAssembly"
+let ab = AppDomain.CurrentDomain.DefineDynamicAssembly(
+ aName,
+ AssemblyBuilderAccess.Run,
+ [| transparent |])
+
+let mb = ab.DefineDynamicModule aName.Name
+let tb = mb.DefineType(
+ "MyDynamicType",
+ TypeAttributes.Public )
+tb.CreateType() |> ignore
+
+printfn $"{ab}\nAssembly attributes:"
+for attr in ab.GetCustomAttributes true do
+ printfn $"\t{attr}"
+
+(* This code example produces the following output:
+
+EmittedAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+Assembly attributes:
+ System.Security.SecurityTransparentAttribute
+ *)
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/DoCallBack/docallback_byref.fs b/snippets/fsharp/System/AppDomain/DoCallBack/docallback_byref.fs
new file mode 100644
index 00000000000..b4d4db6b421
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/DoCallBack/docallback_byref.fs
@@ -0,0 +1,29 @@
+module docallback_byref
+
+//
+open System
+type PingPong() as this =
+ inherit MarshalByRefObject()
+ []
+ val mutable greetings: string
+ do
+ this.greetings <- "PING!"
+
+ // Callback will always execute within defaultDomain due to inheritance from MarshalByRefObject
+ member this.MyCallBack() =
+ let mutable name = AppDomain.CurrentDomain.FriendlyName
+ if name = AppDomain.CurrentDomain.SetupInformation.ApplicationName then
+ name <- "defaultDomain"
+ printfn $"{this.greetings} from {name}"
+
+let otherDomain = AppDomain.CreateDomain "otherDomain"
+
+let pp = new PingPong()
+pp.MyCallBack()
+pp.greetings <- "PONG!"
+otherDomain.DoCallBack(CrossAppDomainDelegate pp.MyCallBack)
+
+// Output:
+// PING! from defaultDomain
+// PONG! from defaultDomain
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/DoCallBack/docallback_byval.fs b/snippets/fsharp/System/AppDomain/DoCallBack/docallback_byval.fs
new file mode 100644
index 00000000000..7dfa01b350b
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/DoCallBack/docallback_byval.fs
@@ -0,0 +1,30 @@
+module docallbackbyval
+
+//
+open System
+
+[]
+type PingPong() as this =
+ []
+ val mutable greetings: string
+ do
+ this.greetings <- "PING!"
+
+ member _.MyCallBack() =
+ let mutable name = AppDomain.CurrentDomain.FriendlyName
+
+ if name = AppDomain.CurrentDomain.SetupInformation.ApplicationName then
+ name <- "defaultDomain"
+ printfn $"{this.greetings} from {name}"
+
+let otherDomain = AppDomain.CreateDomain "otherDomain"
+
+let pp = PingPong()
+pp.MyCallBack()
+pp.greetings <- "PONG!"
+otherDomain.DoCallBack(CrossAppDomainDelegate pp.MyCallBack)
+
+// Output:
+// PING! from defaultDomain
+// PONG! from otherDomain
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/DoCallBack/docallback_static.fs b/snippets/fsharp/System/AppDomain/DoCallBack/docallback_static.fs
new file mode 100644
index 00000000000..4cbab9f5ae2
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/DoCallBack/docallback_static.fs
@@ -0,0 +1,23 @@
+module docallback_static
+
+//
+open System
+
+let mutable greetings = "PONG!"
+
+let myCallBack () =
+ let mutable name = AppDomain.CurrentDomain.FriendlyName
+
+ if name = AppDomain.CurrentDomain.SetupInformation.ApplicationName then
+ name <- "defaultDomain"
+ printfn $"{greetings} from {name}"
+
+let otherDomain = AppDomain.CreateDomain "otherDomain"
+greetings <- "PING!"
+myCallBack ()
+otherDomain.DoCallBack(CrossAppDomainDelegate myCallBack)
+
+// Output:
+// PING! from defaultDomain
+// PONG! from otherDomain
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/DoCallBack/fs.fsproj b/snippets/fsharp/System/AppDomain/DoCallBack/fs.fsproj
new file mode 100644
index 00000000000..91ee090fff6
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/DoCallBack/fs.fsproj
@@ -0,0 +1,12 @@
+
+
+ Exe
+ net48
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/DynamicDirectory/addynamicbase.fs b/snippets/fsharp/System/AppDomain/DynamicDirectory/addynamicbase.fs
new file mode 100644
index 00000000000..a9511197460
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/DynamicDirectory/addynamicbase.fs
@@ -0,0 +1,92 @@
+//
+open System
+open System.Reflection
+open System.Reflection.Emit
+
+type Example() =
+ inherit MarshalByRefObject()
+ member _.Test() =
+ let dynAssem =
+ Assembly.Load "DynamicHelloWorld, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
+
+ let myType = dynAssem.GetType "HelloWorld"
+ myType.InvokeMember("HelloFromAD", BindingFlags.Public |||
+ BindingFlags.Static ||| BindingFlags.InvokeMethod,
+ Type.DefaultBinder, null, null)
+ |> ignore
+
+ static member GenerateDynamicAssembly(location: string) =
+ // Define the dynamic assembly and the module. There is only one
+ // module in this assembly. Note that the call to DefineDynamicAssembly
+ // specifies the location where the assembly will be saved. The
+ // assembly version is 1.0.0.0.
+ let asmName = AssemblyName "DynamicHelloWorld"
+ asmName.Version <- Version "1.0.0.0"
+
+ let ab = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Save, location)
+
+ let moduleName = asmName.Name + ".exe"
+ let mb = ab.DefineDynamicModule(asmName.Name, moduleName)
+
+ // Define the "HelloWorld" type, with one static method.
+ let tb = mb.DefineType("HelloWorld", TypeAttributes.Public)
+ let hello =
+ tb.DefineMethod("HelloFromAD", MethodAttributes.Public ||| MethodAttributes.Static, null, null)
+
+ // The method displays a message that contains the name of the application
+ // domain where the method is executed.
+ let il = hello.GetILGenerator()
+ il.Emit(OpCodes.Ldstr, "Hello from '{0}'!")
+ il.Emit(OpCodes.Call, typeof.GetProperty("CurrentDomain").GetGetMethod())
+ il.Emit(OpCodes.Call, typeof.GetProperty("FriendlyName").GetGetMethod())
+ il.Emit(OpCodes.Call, typeof.GetMethod("WriteLine", [| typeof; typeof |]))
+ il.Emit OpCodes.Ret
+
+ // Complete the HelloWorld type and save the assembly. The assembly
+ // is placed in the location specified by DefineDynamicAssembly.
+ let myType = tb.CreateType()
+ ab.Save moduleName
+
+// Prepare to create a new application domain.
+let setup = AppDomainSetup()
+
+// Set the application name before setting the dynamic base.
+setup.ApplicationName <- "Example"
+
+// Set the location of the base directory where assembly resolution
+// probes for dynamic assemblies. Note that the hash code of the
+// application name is concatenated to the base directory name you
+// supply.
+setup.DynamicBase <- "C:\\DynamicAssemblyDir"
+printfn $"DynamicBase is set to '{setup.DynamicBase}'."
+
+let ad = AppDomain.CreateDomain("MyDomain", null, setup)
+
+// The dynamic directory name is the dynamic base concatenated with
+// the application name: \\
+let dynamicDir = ad.DynamicDirectory
+printfn $"Dynamic directory is '{dynamicDir}'."
+
+// The AssemblyBuilder won't create this directory automatically.
+if not (System.IO.Directory.Exists dynamicDir) then
+ printfn "Creating the dynamic directory."
+ System.IO.Directory.CreateDirectory dynamicDir
+ |> ignore
+
+// Generate a dynamic assembly and store it in the dynamic
+// directory.
+Example.GenerateDynamicAssembly dynamicDir
+
+// Create an instance of the Example class in the application domain,
+// and call its Test method to load the dynamic assembly and use it.
+let ex = ad.CreateInstanceAndUnwrap(typeof.Assembly.FullName, "Example") :?> Example
+ex.Test()
+
+(* This example produces output similar to the following:
+
+DynamicBase is set to 'C:\DynamicAssemblyDir\5e4a7545'.
+Dynamic directory is 'C:\DynamicAssemblyDir\5e4a7545\Example'.
+Creating the dynamic directory.
+Hello from 'MyDomain'!
+ *)
+//
diff --git a/snippets/fsharp/System/AppDomain/DynamicDirectory/fs.fsproj b/snippets/fsharp/System/AppDomain/DynamicDirectory/fs.fsproj
new file mode 100644
index 00000000000..fe75df72fdf
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/DynamicDirectory/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net48
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/ExecuteAssembly/executeassembly.fs b/snippets/fsharp/System/AppDomain/ExecuteAssembly/executeassembly.fs
new file mode 100644
index 00000000000..5ca8c7a6162
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/ExecuteAssembly/executeassembly.fs
@@ -0,0 +1,14 @@
+module executeassembly
+
+//
+open System
+
+let currentDomain = AppDomain.CurrentDomain
+let otherDomain = AppDomain.CreateDomain "otherDomain"
+
+currentDomain.ExecuteAssembly "MyExecutable.exe"
+// Prints "MyExecutable running on [default]"
+
+otherDomain.ExecuteAssembly "MyExecutable.exe"
+// Prints "MyExecutable running on otherDomain"
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/ExecuteAssembly/fs.fsproj b/snippets/fsharp/System/AppDomain/ExecuteAssembly/fs.fsproj
new file mode 100644
index 00000000000..14662c657ea
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/ExecuteAssembly/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/FirstChanceException/example.fs b/snippets/fsharp/System/AppDomain/FirstChanceException/example.fs
new file mode 100644
index 00000000000..509240ff9fe
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/FirstChanceException/example.fs
@@ -0,0 +1,75 @@
+//
+open System
+open System.Runtime.ExceptionServices
+
+let firstChanceHandler _ (e: FirstChanceExceptionEventArgs) =
+ printfn $"FirstChanceException event raised in {AppDomain.CurrentDomain.FriendlyName}: {e.Exception.Message}"
+
+type Worker() =
+ inherit MarshalByRefObject()
+
+ let mutable w = Unchecked.defaultof
+
+ member _.Initialize(count, max) =
+ // Handle the FirstChanceException event in all application domains except
+ // AD1.
+ if count <> 1 then
+ AppDomain.CurrentDomain.FirstChanceException.AddHandler firstChanceHandler
+
+ // Create another application domain, until the maximum is reached.
+ // Field w remains null in the last application domain, as a signal
+ // to TestException().
+ if count < max then
+ let next = count + 1
+ let ad = AppDomain.CreateDomain("AD" + string next)
+ w <-
+ ad.CreateInstanceAndUnwrap(typeof.Assembly.FullName, "Worker") :?> Worker
+ w.Initialize(next, max)
+
+ member _.TestException(handled) =
+ // As long as there is another application domain, call TestException() on
+ // its Worker object. When the last application domain is reached, throw a
+ // handled or unhandled exception.
+ if isNull (box w) then
+ w.TestException handled
+ elif handled then
+ try
+ raise (ArgumentException $"Thrown in {AppDomain.CurrentDomain.FriendlyName}")
+ with :? ArgumentException as ex ->
+ printfn $"ArgumentException caught in {AppDomain.CurrentDomain.FriendlyName}: {ex.Message}"
+ else
+ raise (ArgumentException $"Thrown in {AppDomain.CurrentDomain.FriendlyName}")
+
+AppDomain.CurrentDomain.FirstChanceException.AddHandler firstChanceHandler
+
+// Create a set of application domains, with a Worker object in each one.
+// Each Worker object creates the next application domain.
+let ad = AppDomain.CreateDomain "AD0"
+let w = ad.CreateInstanceAndUnwrap(typeof.Assembly.FullName, "Worker") :?> Worker
+w.Initialize(0, 3)
+
+printfn "\nThe last application domain throws an exception and catches it:\n"
+w.TestException true
+
+try
+ printfn "\nThe last application domain throws an exception and does not catch it:\n"
+ w.TestException false
+with :? ArgumentException as ex ->
+ printfn"ArgumentException caught in {AppDomain.CurrentDomain.FriendlyName}: {ex.Message}"
+
+(* This example produces output similar to the following:
+
+The last application domain throws an exception and catches it:
+
+FirstChanceException event raised in AD3: Thrown in AD3
+ArgumentException caught in AD3: Thrown in AD3
+
+The last application domain throws an exception and does not catch it:
+
+FirstChanceException event raised in AD3: Thrown in AD3
+FirstChanceException event raised in AD2: Thrown in AD3
+FirstChanceException event raised in AD0: Thrown in AD3
+FirstChanceException event raised in Example.exe: Thrown in AD3
+ArgumentException caught in Example.exe: Thrown in AD3
+ *)
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/FirstChanceException/fs.fsproj b/snippets/fsharp/System/AppDomain/FirstChanceException/fs.fsproj
new file mode 100644
index 00000000000..2b336f60d41
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/FirstChanceException/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/GetAssemblies/adgetassemblies.fs b/snippets/fsharp/System/AppDomain/GetAssemblies/adgetassemblies.fs
new file mode 100644
index 00000000000..015cffd435f
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/GetAssemblies/adgetassemblies.fs
@@ -0,0 +1,19 @@
+//
+open System
+
+let currentDomain = AppDomain.CurrentDomain
+//Provide the current application domain evidence for the assembly.
+let asEvidence = currentDomain.Evidence
+//Load the assembly from the application directory using a simple name.
+
+//Create an assembly called CustomLibrary to run this sample.
+currentDomain.Load("CustomLibrary", asEvidence)
+
+//Make an array for the list of assemblies.
+let assems = currentDomain.GetAssemblies()
+
+//List the assemblies in the current application domain.
+printfn "List of assemblies loaded in current appdomain:"
+for assem in assems do
+ printfn $"{assem}"
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/GetAssemblies/fs.fsproj b/snippets/fsharp/System/AppDomain/GetAssemblies/fs.fsproj
new file mode 100644
index 00000000000..d11dd7611e0
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/GetAssemblies/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net48
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/GetData/adgetdata.fs b/snippets/fsharp/System/AppDomain/GetData/adgetdata.fs
new file mode 100644
index 00000000000..696f95d43ba
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/GetData/adgetdata.fs
@@ -0,0 +1,23 @@
+//
+open System
+
+// appdomain setup information
+let currentDomain = AppDomain.CurrentDomain
+
+//Create a new value pair for the appdomain
+currentDomain.SetData("ADVALUE", "Example value")
+
+//get the value specified in the setdata method
+currentDomain.GetData "ADVALUE"
+|> printfn "ADVALUE is: %O"
+
+//get a system value specified at appdomainsetup
+currentDomain.GetData "LOADER_OPTIMIZATION"
+|> printfn "System value for loader optimization: %O"
+
+(* This code example produces the following output:
+
+ADVALUE is: Example value
+System value for loader optimization: NotSpecified
+*)
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/GetData/fs.fsproj b/snippets/fsharp/System/AppDomain/GetData/fs.fsproj
new file mode 100644
index 00000000000..98ec9e90abf
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/GetData/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/Id/fs.fsproj b/snippets/fsharp/System/AppDomain/Id/fs.fsproj
new file mode 100644
index 00000000000..304d2fa939e
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/Id/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net48
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/Id/source.fs b/snippets/fsharp/System/AppDomain/Id/source.fs
new file mode 100644
index 00000000000..e48ed536b67
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/Id/source.fs
@@ -0,0 +1,25 @@
+//
+open System
+
+// This method has the same signature as the CrossAppDomainDelegate,
+// so that it can be executed easily in the new application domain.
+let showDomainInfo () =
+ let ad = AppDomain.CurrentDomain
+ printfn $"\nFriendlyName: {ad.FriendlyName}"
+ printfn $"Id: {ad.Id}"
+ printfn $"IsDefaultAppDomain: {ad.IsDefaultAppDomain()}"
+
+// The following attribute indicates to the loader that assemblies
+// in the global assembly cache should be shared across multiple
+// application domains.
+[]
+[]
+let main _ =
+ // Show information for the default application domain.
+ showDomainInfo ()
+
+ // Create a new application domain and display its information.
+ let newDomain = AppDomain.CreateDomain "MyMultiDomain"
+ newDomain.DoCallBack(CrossAppDomainDelegate showDomainInfo)
+ 0
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/IsFullyTrusted/example.fs b/snippets/fsharp/System/AppDomain/IsFullyTrusted/example.fs
new file mode 100644
index 00000000000..941e8f3bf27
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/IsFullyTrusted/example.fs
@@ -0,0 +1,48 @@
+//
+open System
+open System.IO
+open System.Security
+open System.Security.Policy
+
+type Worker() =
+ inherit MarshalByRefObject()
+ member _.TestIsFullyTrusted() =
+ let ad = AppDomain.CurrentDomain
+ printfn $"\nApplication domain '{ad.FriendlyName}': IsFullyTrusted = {ad.IsFullyTrusted}"
+
+ printfn $" IsFullyTrusted = {typeof.Assembly.IsFullyTrusted} for the current assembly"
+
+ printfn $" IsFullyTrusted = {typeof.Assembly.IsFullyTrusted} for mscorlib"
+
+// ------------ Helper function ---------------------------------------
+let getInternetSandbox () =
+ // Create the permission set to grant to all assemblies.
+ let hostEvidence = Evidence()
+ hostEvidence.AddHostEvidence(Zone System.Security.SecurityZone.Internet)
+ let pset = SecurityManager.GetStandardSandbox hostEvidence
+
+ // Identify the folder to use for the sandbox.
+ let ads = AppDomainSetup()
+ ads.ApplicationBase <- Directory.GetCurrentDirectory()
+
+ // Create the sandboxed application domain.
+ AppDomain.CreateDomain("Sandbox", hostEvidence, ads, pset, null)
+
+let w = Worker()
+w.TestIsFullyTrusted()
+
+let adSandbox = getInternetSandbox()
+let w2 =
+ adSandbox.CreateInstanceAndUnwrap(typeof.Assembly.FullName, typeof.FullName) :?> Worker
+w2.TestIsFullyTrusted()
+(* This example produces output similar to the following:
+
+Application domain 'Example.exe': IsFullyTrusted = True
+ IsFullyTrusted = True for the current assembly
+ IsFullyTrusted = True for mscorlib
+
+Application domain 'Sandbox': IsFullyTrusted = False
+ IsFullyTrusted = False for the current assembly
+ IsFullyTrusted = True for mscorlib
+ *)
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/IsFullyTrusted/fs.fsproj b/snippets/fsharp/System/AppDomain/IsFullyTrusted/fs.fsproj
new file mode 100644
index 00000000000..58571a6b6b8
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/IsFullyTrusted/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net48
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/Load/fs.fsproj b/snippets/fsharp/System/AppDomain/Load/fs.fsproj
new file mode 100644
index 00000000000..e1045d7ad96
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/Load/fs.fsproj
@@ -0,0 +1,11 @@
+
+
+ Exe
+ net48
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/Load/loadraw.fs b/snippets/fsharp/System/AppDomain/Load/loadraw.fs
new file mode 100644
index 00000000000..62fc00aa06d
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/Load/loadraw.fs
@@ -0,0 +1,62 @@
+module loadraw
+
+//
+open System
+open System.IO
+open System.Reflection
+open System.Reflection.Emit
+
+let instantiateMyType (domain: AppDomain) =
+ try
+ // You must supply a valid fully qualified assembly name here.
+ domain.CreateInstance("Assembly text name, Version, Culture, PublicKeyToken", "MyType")
+ |> ignore
+ with e ->
+ printfn $"{e.Message}"
+
+// Loads the content of a file to a byte array.
+let loadFile filename =
+ use fs = new FileStream(filename, FileMode.Open)
+ let buffer = Array.zeroCreate (int fs.Length)
+ fs.Read(buffer, 0, buffer.Length) |> ignore
+ fs.Close()
+ buffer
+
+// Creates a dynamic assembly with symbol information
+// and saves them to temp.dll and temp.pdb
+let emitAssembly (domain: AppDomain) =
+ let assemblyName = AssemblyName()
+ assemblyName.Name <- "MyAssembly"
+
+ let assemblyBuilder = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save)
+ let moduleBuilder = assemblyBuilder.DefineDynamicModule("MyModule", "temp.dll", true)
+ let typeBuilder = moduleBuilder.DefineType("MyType", TypeAttributes.Public)
+
+ let constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, null)
+ let ilGenerator = constructorBuilder.GetILGenerator()
+ ilGenerator.EmitWriteLine "MyType instantiated!"
+ ilGenerator.Emit OpCodes.Ret
+
+ typeBuilder.CreateType() |> ignore
+
+ assemblyBuilder.Save "temp.dll"
+
+let myResolver (sender: obj) (args: ResolveEventArgs) =
+ let domain = sender :?> AppDomain
+
+ // Once the files are generated, this call is
+ // actually no longer necessary.
+ emitAssembly domain
+
+ let rawAssembly = loadFile "temp.dll"
+ let rawSymbolStore = loadFile "temp.pdb"
+ domain.Load(rawAssembly, rawSymbolStore)
+
+let currentDomain = AppDomain.CurrentDomain
+
+instantiateMyType currentDomain // Failed!
+
+currentDomain.add_AssemblyResolve (ResolveEventHandler myResolver)
+
+instantiateMyType currentDomain // OK!
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/Load/source.fs b/snippets/fsharp/System/AppDomain/Load/source.fs
new file mode 100644
index 00000000000..f809c2882fd
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/Load/source.fs
@@ -0,0 +1,6 @@
+open System
+//
+let ad = AppDomain.CreateDomain "ChildDomain"
+ad.Load "MyAssembly"
+//
+|> ignore
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/Overview/AppDomainX.fs b/snippets/fsharp/System/AppDomain/Overview/AppDomainX.fs
new file mode 100644
index 00000000000..ed64e355582
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/Overview/AppDomainX.fs
@@ -0,0 +1,78 @@
+//
+open System
+open System.Reflection
+open System.Threading
+
+//
+// Because this class is derived from MarshalByRefObject, a proxy
+// to a MarshalByRefType object can be returned across an AppDomain
+// boundary.
+type MarshalByRefType() =
+ inherit MarshalByRefObject()
+
+ // Call this method via a proxy.
+ member _.SomeMethod(callingDomainName) =
+ // Get this AppDomain's settings and display some of them.
+ let ads = AppDomain.CurrentDomain.SetupInformation
+ printfn $"AppName={ads.ApplicationName}, AppBase={ads.ApplicationBase}, ConfigFile={ads.ConfigurationFile}"
+
+ // Display the name of the calling AppDomain and the name
+ // of the second domain.
+ // NOTE: The application's thread has transitioned between
+ // AppDomains.
+ printfn $"Calling from '{callingDomainName}' to '{Thread.GetDomain().FriendlyName}'."
+//
+
+//
+// Get and display the friendly name of the default AppDomain.
+let callingDomainName = Thread.GetDomain().FriendlyName
+printfn $"{callingDomainName}"
+
+// Get and display the full name of the EXE assembly.
+let exeAssembly = Assembly.GetEntryAssembly().FullName
+printfn $"{exeAssembly}"
+
+// Construct and initialize settings for a second AppDomain.
+let ads = AppDomainSetup()
+ads.ApplicationBase <- AppDomain.CurrentDomain.BaseDirectory
+
+ads.DisallowBindingRedirects <- false
+ads.DisallowCodeDownload <- true
+ads.ConfigurationFile <-
+ AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
+
+// Create the second AppDomain.
+let ad2 = AppDomain.CreateDomain("AD #2", null, ads)
+
+// Create an instance of MarshalbyRefType in the second AppDomain.
+// A proxy to the object is returned.
+let mbrt =
+ ad2.CreateInstanceAndUnwrap(
+ exeAssembly,
+ typeof.FullName) :?> MarshalByRefType
+
+// Call a method on the object via the proxy, passing the
+// default AppDomain's friendly name in as a parameter.
+mbrt.SomeMethod callingDomainName
+
+// Unload the second AppDomain. This deletes its object and
+// invalidates the proxy object.
+AppDomain.Unload ad2
+try
+ // Call the method again. Note that this time it fails
+ // because the second AppDomain was unloaded.
+ mbrt.SomeMethod callingDomainName
+ printfn "Sucessful call."
+with :? AppDomainUnloadedException ->
+ printfn "Failed call this is expected."
+//
+
+(* This code produces output similar to the following:
+
+AppDomainX.exe
+AppDomainX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
+AppName=, AppBase=C:\AppDomain\bin, ConfigFile=C:\AppDomain\bin\AppDomainX.exe.config
+Calling from 'AppDomainX.exe' to 'AD #2'.
+Failed call this is expected.
+ *)
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/Overview/fs.fsproj b/snippets/fsharp/System/AppDomain/Overview/fs.fsproj
new file mode 100644
index 00000000000..2fcd91e168a
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/Overview/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net48
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/ReflectionOnlyGetAssemblies/fs.fsproj b/snippets/fsharp/System/AppDomain/ReflectionOnlyGetAssemblies/fs.fsproj
new file mode 100644
index 00000000000..79d8660d8a4
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/ReflectionOnlyGetAssemblies/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/ReflectionOnlyGetAssemblies/reflectiononly.fs b/snippets/fsharp/System/AppDomain/ReflectionOnlyGetAssemblies/reflectiononly.fs
new file mode 100644
index 00000000000..f768a1be196
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/ReflectionOnlyGetAssemblies/reflectiononly.fs
@@ -0,0 +1,27 @@
+//
+open System
+open System.Reflection
+open System.Timers
+
+// Get the assembly display name for System.dll, the assembly
+// that contains System.Timers.Timer. Note that this causes
+// System.dll to be loaded into the execution context.
+let displayName = typeof.Assembly.FullName
+
+// Load System.dll into the reflection-only context. Note that
+// if you obtain the display name (for example, by running this
+// example program), and enter it as a literal string in the
+// preceding line of code, you can load System.dll into the
+// reflection-only context without loading it into the execution
+// context.
+Assembly.ReflectionOnlyLoad displayName |> ignore
+
+// Display the assemblies loaded into the execution and
+// reflection-only contexts. System.dll appears in both contexts.
+printfn "------------- Execution Context --------------"
+for a in AppDomain.CurrentDomain.GetAssemblies() do
+ printfn $"\t{a.GetName()}"
+printfn "------------- Reflection-only Context --------------"
+for a in AppDomain.CurrentDomain.ReflectionOnlyGetAssemblies() do
+ printfn $"\t{a.GetName()}"
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/SetAppDomainPolicy/adsetappdomainpolicy.fs b/snippets/fsharp/System/AppDomain/SetAppDomainPolicy/adsetappdomainpolicy.fs
new file mode 100644
index 00000000000..7cb9b02ae51
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/SetAppDomainPolicy/adsetappdomainpolicy.fs
@@ -0,0 +1,32 @@
+//
+open System
+open System.Security
+open System.Security.Policy
+open System.Security.Permissions
+
+// Create a new application domain.
+let domain = AppDomain.CreateDomain "MyDomain"
+
+// Create a new AppDomain PolicyLevel.
+let polLevel = PolicyLevel.CreateAppDomainLevel()
+// Create a new, empty permission set.
+let permSet = PermissionSet PermissionState.None
+// Add permission to execute code to the permission set.
+permSet.AddPermission(SecurityPermission SecurityPermissionFlag.Execution) |> ignore
+// Give the policy level's root code group a new policy statement based
+// on the new permission set.
+polLevel.RootCodeGroup.PolicyStatement <- PolicyStatement permSet
+// Give the new policy level to the application domain.
+domain.SetAppDomainPolicy polLevel
+
+// Try to execute the assembly.
+try
+ // This will throw a PolicyException if the executable tries to
+ // access any resources like file I/O or tries to create a window.
+ domain.ExecuteAssembly "Assemblies\\MyWindowsExe.exe"
+ |> ignore
+with :? PolicyException as e ->
+ printfn $"PolicyException: {e.Message}"
+
+AppDomain.Unload domain
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/SetAppDomainPolicy/fs.fsproj b/snippets/fsharp/System/AppDomain/SetAppDomainPolicy/fs.fsproj
new file mode 100644
index 00000000000..be4144a975d
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/SetAppDomainPolicy/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net48
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/SetPrincipalPolicy/adprincipal.fs b/snippets/fsharp/System/AppDomain/SetPrincipalPolicy/adprincipal.fs
new file mode 100644
index 00000000000..9373d987354
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/SetPrincipalPolicy/adprincipal.fs
@@ -0,0 +1,44 @@
+//
+open System
+open System.Security.Principal
+open System.Threading
+
+let printPrincipalInformation () =
+ let curPrincipal = Thread.CurrentPrincipal
+ if curPrincipal <> null then
+ printfn $"Type: {curPrincipal.GetType().Name}"
+ printfn $"Name: {curPrincipal.Identity.Name}"
+ printfn $"Authenticated: {curPrincipal.Identity.IsAuthenticated}\n"
+
+[]
+let main _ =
+ // Create a new thread with a generic principal.
+ let t = Thread(ThreadStart printPrincipalInformation)
+ t.Start()
+ t.Join()
+
+ // Set the principal policy to WindowsPrincipal.
+ let currentDomain = AppDomain.CurrentDomain
+ currentDomain.SetPrincipalPolicy PrincipalPolicy.WindowsPrincipal
+
+ // The new thread will have a Windows principal representing the
+ // current user.
+ let t = Thread(ThreadStart printPrincipalInformation)
+ t.Start()
+ t.Join()
+
+ // Create a principal to use for new threads.
+ let identity = GenericIdentity "NewUser"
+ let principal = GenericPrincipal(identity, null)
+ currentDomain.SetThreadPrincipal principal
+
+ // Create a new thread with the principal created above.
+ let t = Thread(ThreadStart printPrincipalInformation)
+ t.Start()
+ t.Join()
+
+ // Wait for user input before terminating.
+ Console.ReadLine() |> ignore
+ 0
+
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/SetPrincipalPolicy/fs.fsproj b/snippets/fsharp/System/AppDomain/SetPrincipalPolicy/fs.fsproj
new file mode 100644
index 00000000000..eb1dd861929
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/SetPrincipalPolicy/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/SetShadowCopyFiles/adproperties.fs b/snippets/fsharp/System/AppDomain/SetShadowCopyFiles/adproperties.fs
new file mode 100644
index 00000000000..ad81562cb3c
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/SetShadowCopyFiles/adproperties.fs
@@ -0,0 +1,52 @@
+//
+open System
+
+let setup = AppDomainSetup()
+// Shadow copying will not work unless the application has a name.
+setup.ApplicationName = "MyApplication"
+
+//Create evidence for the new application domain from evidence of
+// current application domain.
+let adevidence = AppDomain.CurrentDomain.Evidence
+
+// Create a new application domain.
+let domain = AppDomain.CreateDomain("MyDomain", adevidence, setup)
+
+// MyAssembly.dll is located in the Assemblies subdirectory.
+domain.AppendPrivatePath "Assemblies"
+// MyOtherAssembly.dll and MyThirdAssembly.dll are located in the
+// MoreAssemblies subdirectory.
+domain.AppendPrivatePath "MoreAssemblies"
+// Display the relative search path.
+printfn $"RelativeSearchPath: {domain.RelativeSearchPath}"
+// Because Load returns an Assembly object, the assemblies must be
+// loaded into the current domain as well. This will fail unless the
+// current domain also has these directories in its search path.
+AppDomain.CurrentDomain.AppendPrivatePath "Assemblies"
+AppDomain.CurrentDomain.AppendPrivatePath "MoreAssemblies"
+
+// Save shadow copies to C:\Cache
+domain.SetCachePath "C:\\Cache"
+// Shadow copy only the assemblies in the Assemblies directory.
+domain.SetShadowCopyPath(domain.BaseDirectory + "Assemblies")
+// Turn shadow copying on.
+domain.SetShadowCopyFiles()
+printfn $"ShadowCopyFiles turned on: {domain.ShadowCopyFiles}"
+
+// This will be copied.
+// You must supply a valid fully qualified assembly name here.
+domain.Load "Assembly1 text name, Version, Culture, PublicKeyToken" |> ignore
+// This will not be copied.
+// You must supply a valid fully qualified assembly name here.
+domain.Load "Assembly2 text name, Version, Culture, PublicKeyToken" |> ignore
+
+// When the shadow copy path is cleared, the CLR will make shadow copies
+// of all private assemblies.
+domain.ClearShadowCopyPath()
+// MoreAssemblies\MyThirdAssembly.dll should be shadow copied this time.
+// You must supply a valid fully qualified assembly name here.
+domain.Load "Assembly3 text name, Version, Culture, PublicKeyToken" |> ignore
+
+// Unload the domain.
+AppDomain.Unload domain
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/SetShadowCopyFiles/fs.fsproj b/snippets/fsharp/System/AppDomain/SetShadowCopyFiles/fs.fsproj
new file mode 100644
index 00000000000..b7c1617d0d9
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/SetShadowCopyFiles/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net48
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/SetShadowCopyPath/adshadowcopy.fs b/snippets/fsharp/System/AppDomain/SetShadowCopyPath/adshadowcopy.fs
new file mode 100644
index 00000000000..5f5fecc2e0e
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/SetShadowCopyPath/adshadowcopy.fs
@@ -0,0 +1,51 @@
+//
+open System
+
+let setup = AppDomainSetup()
+// Shadow copying will not work unless the application has a name.
+setup.ApplicationName <- "MyApplication"
+
+//Create evidence for the new application domain from evidence of
+// current application domain.
+let adevidence = AppDomain.CurrentDomain.Evidence
+
+// Create a new application domain.
+let domain = AppDomain.CreateDomain("MyDomain", adevidence, setup)
+
+// MyAssembly.dll is located in the Assemblies subdirectory.
+domain.AppendPrivatePath "Assemblies"
+// MyOtherAssembly.dll and MyThirdAssembly.dll are located in the
+// MoreAssemblies subdirectory.
+domain.AppendPrivatePath "MoreAssemblies"
+// Display the relative search path.
+printfn $"RelativeSearchPath: {domain.RelativeSearchPath}"
+// Because Load returns an Assembly object, the assemblies must be
+// loaded into the current domain as well. This will fail unless the
+// current domain also has these directories in its search path.
+AppDomain.CurrentDomain.AppendPrivatePath "Assemblies"
+AppDomain.CurrentDomain.AppendPrivatePath "MoreAssemblies"
+
+// Save shadow copies to C:\Cache
+domain.SetCachePath "C:\\Cache"
+// Shadow copy only the assemblies in the Assemblies directory.
+domain.SetShadowCopyPath(domain.BaseDirectory + "Assemblies")
+// Turn shadow copying on.
+domain.SetShadowCopyFiles()
+
+// This will be copied.
+// You must supply a valid fully qualified assembly name here.
+domain.Load "Assembly1 text name, Version, Culture, PublicKeyToken" |> ignore
+// This will not be copied.
+// You must supply a valid fully qualified assembly name here.
+domain.Load "Assembly2 text name, Version, Culture, PublicKeyToken" |> ignore
+
+// When the shadow copy path is cleared, the CLR will make shadow copies
+// of all private assemblies.
+domain.ClearShadowCopyPath()
+// MoreAssemblies\MyThirdAssembly.dll should be shadow copied this time.
+// You must supply a valid fully qualified assembly name here.
+domain.Load "Assembly3 text name, Version, Culture, PublicKeyToken" |> ignore
+
+// Unload the domain.
+AppDomain.Unload domain
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/SetShadowCopyPath/fs.fsproj b/snippets/fsharp/System/AppDomain/SetShadowCopyPath/fs.fsproj
new file mode 100644
index 00000000000..bffd01edfce
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/SetShadowCopyPath/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net48
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/ToString/adtostring.fs b/snippets/fsharp/System/AppDomain/ToString/adtostring.fs
new file mode 100644
index 00000000000..15b25570f7c
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/ToString/adtostring.fs
@@ -0,0 +1,19 @@
+//
+open System
+
+// Create application domain setup information
+let domaininfo = AppDomainSetup()
+
+//Create evidence for the new appdomain from evidence of the current application domain
+let adevidence = AppDomain.CurrentDomain.Evidence
+
+// Create appdomain
+let domain = AppDomain.CreateDomain("MyDomain", adevidence, domaininfo)
+
+// Write out application domain information
+printfn $"Host domain: {AppDomain.CurrentDomain.FriendlyName}"
+printfn $"child domain: {domain.FriendlyName}"
+printfn $"child domain name using ToString:{domain}\n"
+
+AppDomain.Unload domain
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/ToString/fs.fsproj b/snippets/fsharp/System/AppDomain/ToString/fs.fsproj
new file mode 100644
index 00000000000..086a99d18ea
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/ToString/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net48
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/TypeResolve/fs.fsproj b/snippets/fsharp/System/AppDomain/TypeResolve/fs.fsproj
new file mode 100644
index 00000000000..d9ff98ae4d5
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/TypeResolve/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net48
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/TypeResolve/typeresolve.fs b/snippets/fsharp/System/AppDomain/TypeResolve/typeresolve.fs
new file mode 100644
index 00000000000..06b9dd066f2
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/TypeResolve/typeresolve.fs
@@ -0,0 +1,58 @@
+//
+open System
+open System.Reflection
+open System.Reflection.Emit
+
+let currDom = AppDomain.CurrentDomain
+
+// Create a dynamic assembly with one module, to be saved to
+// disk (AssemblyBuilderAccess.Save).
+//
+let aName = AssemblyName()
+aName.Name <- "Transient"
+let moduleName = aName.Name + ".dll"
+let ab = currDom.DefineDynamicAssembly(aName, AssemblyBuilderAccess.Save)
+
+let handleTypeResolve _ _ =
+ printfn "TypeResolve event handler."
+
+ // Save the dynamic assembly, and then load it using its
+ // display name. Return the loaded assembly.
+ ab.Save moduleName
+ Assembly.Load ab.FullName
+
+let mb = ab.DefineDynamicModule(aName.Name, moduleName)
+
+// The dynamic assembly has just one dummy type, to demonstrate
+// type resolution.
+let tb = mb.DefineType "Example"
+tb.CreateType() |> ignore
+
+// First, try to load the type without saving the dynamic
+// assembly and without hooking up the TypeResolve event. The
+// type cannot be loaded.
+try
+ let temp = Type.GetType("Example", true)
+ printfn $"Loaded type {temp}."
+with :? TypeLoadException ->
+ printfn "Loader could not resolve the type."
+
+// Hook up the TypeResolve event.
+//
+currDom.add_TypeResolve(ResolveEventHandler handleTypeResolve)
+
+// Now try to load the type again. The TypeResolve event is
+// raised, the dynamic assembly is saved, and the dummy type is
+// loaded successfully. Display it to the console, and create
+// an instance.
+let t = Type.GetType("Example", true)
+printfn $"Loaded type \"{t}\"."
+let o = Activator.CreateInstance t
+
+(* This code example produces the following output:
+
+Loader could not resolve the type.
+TypeResolve event handler.
+Loaded type "Example".
+ *)
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/UnhandledException/fs.fsproj b/snippets/fsharp/System/AppDomain/UnhandledException/fs.fsproj
new file mode 100644
index 00000000000..9540379a6b2
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/UnhandledException/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/UnhandledException/unhandledexception.fs b/snippets/fsharp/System/AppDomain/UnhandledException/unhandledexception.fs
new file mode 100644
index 00000000000..83ff4b009db
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/UnhandledException/unhandledexception.fs
@@ -0,0 +1,30 @@
+//
+open System
+open System.Security.Permissions
+
+let myHandler _ (args: UnhandledExceptionEventArgs) =
+ let e = args.ExceptionObject :?> Exception
+ printfn $"MyHandler caught : {e.Message}"
+ printfn $"Runtime terminating: {args.IsTerminating}"
+
+[]
+let main _ =
+ let currentDomain = AppDomain.CurrentDomain
+ currentDomain.UnhandledException.AddHandler(UnhandledExceptionEventHandler myHandler)
+
+ try
+ failwith "1"
+ with e ->
+ printfn $"Catch clause caught : {e.Message} \n"
+
+ failwith "2"
+
+// The example displays the following output:
+// Catch clause caught : 1
+//
+// MyHandler caught : 2
+// Runtime terminating: True
+//
+// Unhandled Exception: System.Exception: 2
+// at Example.main()
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/Unload/adunload.fs b/snippets/fsharp/System/AppDomain/Unload/adunload.fs
new file mode 100644
index 00000000000..516f492e5b0
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/Unload/adunload.fs
@@ -0,0 +1,22 @@
+//
+open System
+
+//Create evidence for the new appdomain.
+let adevidence = AppDomain.CurrentDomain.Evidence
+
+// Create the new application domain.
+let domain = AppDomain.CreateDomain("MyDomain", adevidence)
+
+printfn $"Host domain: {AppDomain.CurrentDomain.FriendlyName}"
+printfn $"child domain: {domain.FriendlyName}"
+// Unload the application domain.
+AppDomain.Unload domain
+
+try
+ printfn ""
+ // Note that the following statement creates an exception because the domain no longer exists.
+ printfn $"child domain: {domain.FriendlyName}"
+
+with :? AppDomainUnloadedException ->
+ printfn "The appdomain MyDomain does not exist."
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomain/Unload/fs.fsproj b/snippets/fsharp/System/AppDomain/Unload/fs.fsproj
new file mode 100644
index 00000000000..9dd5c83decd
--- /dev/null
+++ b/snippets/fsharp/System/AppDomain/Unload/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net48
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomainSetup/AppDomainInitializer/fs.fsproj b/snippets/fsharp/System/AppDomainSetup/AppDomainInitializer/fs.fsproj
new file mode 100644
index 00000000000..304d2fa939e
--- /dev/null
+++ b/snippets/fsharp/System/AppDomainSetup/AppDomainInitializer/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net48
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomainSetup/AppDomainInitializer/source.fs b/snippets/fsharp/System/AppDomainSetup/AppDomainInitializer/source.fs
new file mode 100644
index 00000000000..b3bb02bb7be
--- /dev/null
+++ b/snippets/fsharp/System/AppDomainSetup/AppDomainInitializer/source.fs
@@ -0,0 +1,49 @@
+//
+open System
+open System.Security.Policy
+
+// Get a reference to the default application domain.
+let current = AppDomain.CurrentDomain
+
+// Create the AppDomainSetup that will be used to set up the child
+// AppDomain.
+let ads = AppDomainSetup()
+
+// Use the evidence from the default application domain to
+// create evidence for the child application domain.
+let ev = Evidence current.Evidence
+
+// The callback function invoked when the child application domain is
+// initialized. The function simply displays the arguments that were
+// passed to it.
+let appDomainInit args =
+ printfn $"AppDomain \"{AppDomain.CurrentDomain.FriendlyName}\" is initialized with these arguments:"
+ for arg in args do
+ printfn $" {arg}"
+
+// Create an AppDomainInitializer delegate that represents the
+// callback method, AppDomainInit. Assign this delegate to the
+// AppDomainInitializer property of the AppDomainSetup object.
+let adi = AppDomainInitializer appDomainInit
+ads.AppDomainInitializer <- adi
+
+// Create an array of strings to pass as arguments to the callback
+// method. Assign the array to the AppDomainInitializerArguments
+// property.
+let initArgs = [| "String1"; "String2" |]
+ads.AppDomainInitializerArguments <- initArgs
+
+// Create a child application domain named "ChildDomain", using
+// the evidence and the AppDomainSetup object.
+let ad = AppDomain.CreateDomain("ChildDomain", ev, ads)
+
+printfn "Press the Enter key to exit the example program."
+stdin.ReadLine() |> ignore
+
+(* This code example produces the following output:
+
+AppDomain "ChildDomain" is initialized with these arguments:
+ String1
+ String2
+ *)
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomainSetup/ApplicationName/admultidomain.fs b/snippets/fsharp/System/AppDomainSetup/ApplicationName/admultidomain.fs
new file mode 100644
index 00000000000..c15113feee9
--- /dev/null
+++ b/snippets/fsharp/System/AppDomainSetup/ApplicationName/admultidomain.fs
@@ -0,0 +1,37 @@
+//
+open System
+open System.Reflection
+
+type Worker() =
+ inherit MarshalByRefObject()
+ member internal _.TestLoad() =
+ // You must supply a valid fully qualified assembly name here.
+ Assembly.Load "Text assembly name, Culture, PublicKeyToken, Version" |> ignore
+ for assem in AppDomain.CurrentDomain.GetAssemblies() do
+ printfn $"{assem.FullName}"
+
+// The following attribute indicates to loader that multiple application
+// domains are used in this application.
+[]
+[]
+let main _ =
+ // Create application domain setup information for new application domain.
+ let domaininfo = AppDomainSetup()
+ domaininfo.ApplicationBase <- System.Environment.CurrentDirectory
+ domaininfo.ApplicationName <- "MyMultiDomain Application"
+
+ //Create evidence for the new appdomain from evidence of current application domain.
+ let adevidence = AppDomain.CurrentDomain.Evidence
+
+ // Create appdomain.
+ let newDomain = AppDomain.CreateDomain("MyMultiDomain", adevidence, domaininfo)
+
+ // Load an assembly into the new application domain.
+ let w =
+ newDomain.CreateInstanceAndUnwrap(typeof.Assembly.GetName().Name, "Worker" ) :?> Worker
+ w.TestLoad()
+
+ //Unload the application domain, which also unloads the assembly.
+ AppDomain.Unload newDomain
+ 0
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomainSetup/ApplicationName/fs.fsproj b/snippets/fsharp/System/AppDomainSetup/ApplicationName/fs.fsproj
new file mode 100644
index 00000000000..1a7f0e5a60c
--- /dev/null
+++ b/snippets/fsharp/System/AppDomainSetup/ApplicationName/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net48
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomainUnloadedException/Overview/Sample.fs b/snippets/fsharp/System/AppDomainUnloadedException/Overview/Sample.fs
new file mode 100644
index 00000000000..4f51acad353
--- /dev/null
+++ b/snippets/fsharp/System/AppDomainUnloadedException/Overview/Sample.fs
@@ -0,0 +1,71 @@
+//
+open System
+open System.Threading
+
+// TestClass derives from MarshalByRefObject, so it can be marshaled
+// across application domain boundaries.
+type TestClass() =
+ inherit MarshalByRefObject()
+ member _.UnloadCurrentDomain (state: obj) =
+ printfn $"\nUnloading the current AppDomain{state}."
+
+ // Unload the current application domain. This causes
+ // an AppDomainUnloadedException to be thrown.
+ //
+ AppDomain.Unload AppDomain.CurrentDomain
+
+let threadProc (state: obj) =
+ // Create an application domain, and create an instance
+ // of TestClass in the application domain. The first
+ // parameter of CreateInstanceAndUnwrap is the name of
+ // this executable. If you compile the example code using
+ // any name other than "Sample.exe", you must change the
+ // parameter appropriately.
+ let ad = AppDomain.CreateDomain "TestDomain"
+ let tc = ad.CreateInstanceAndUnwrap("Sample", "TestClass") :?> TestClass
+
+ // In the new application domain, execute a method that
+ // unloads the AppDomain. The unhandled exception this
+ // causes ends the current thread.
+ tc.UnloadCurrentDomain state
+
+ printfn "ThreadProc: This message is never displayed."
+
+// 1. Queue ThreadProc as a task for a ThreadPool thread.
+ThreadPool.QueueUserWorkItem(threadProc, " from a ThreadPool thread") |> ignore
+Thread.Sleep 1000
+
+// 2. Execute ThreadProc on an ordinary thread.
+let t = Thread(ParameterizedThreadStart threadProc)
+t.Start " from an ordinary thread"
+t.Join()
+
+// 3. Execute ThreadProc on the main thread, with
+// exception handling.
+try
+ threadProc " from the main application thread (handled)"
+with :? AppDomainUnloadedException as adue ->
+ printfn $"Main thread caught AppDomainUnloadedException: {adue.Message}"
+
+// 4. Execute ThreadProc on the main thread without
+// exception handling.
+threadProc " from the main application thread (unhandled)"
+
+printfn "Main: This message is never displayed."
+
+(* This code example produces output similar to the following:
+Unloading the current AppDomain from a ThreadPool thread.
+
+Unloading the current AppDomain from an ordinary thread.
+
+Unloading the current AppDomain from the main application thread (handled).
+Main thread caught AppDomainUnloadedException: The application domain in which the thread was running has been unloaded.
+
+Unloading the current AppDomain from the main application thread (unhandled).
+
+Unhandled Exception: System.AppDomainUnloadedException: The application domain in which the thread was running has been unloaded.
+ at TestClass.UnloadCurrentDomain(Object state)
+ at Example.ThreadProc(Object state)
+ at Example.main()
+ *)
+//
\ No newline at end of file
diff --git a/snippets/fsharp/System/AppDomainUnloadedException/Overview/fs.fsproj b/snippets/fsharp/System/AppDomainUnloadedException/Overview/fs.fsproj
new file mode 100644
index 00000000000..19155c576e0
--- /dev/null
+++ b/snippets/fsharp/System/AppDomainUnloadedException/Overview/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/xml/System/AppDomain.xml b/xml/System/AppDomain.xml
index 3c22ab2e6bc..166e1374975 100644
--- a/xml/System/AppDomain.xml
+++ b/xml/System/AppDomain.xml
@@ -109,6 +109,7 @@ Application domains, which are represented by objects, h
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomainX/cpp/AppDomainX.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/Overview/AppDomainX.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/Overview/AppDomainX.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomainX/VB/AppDomainX.vb" id="Snippet1":::
]]>
@@ -444,6 +445,7 @@ Application domains, which are represented by objects, h
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_AssemblyLoad/CPP/assemblyload.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/AssemblyLoad/assemblyload.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/AssemblyLoad/assemblyload.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_AssemblyLoad/VB/assemblyload.vb" id="Snippet1":::
]]>
@@ -531,6 +533,7 @@ Application domains, which are represented by objects, h
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AssemblyResolve/CPP/assemblyresolve.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/AssemblyResolve/assemblyresolve.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/AssemblyResolve/assemblyresolve.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AssemblyResolve/VB/assemblyresolve.vb" id="Snippet1":::
]]>
@@ -600,6 +603,7 @@ Application domains, which are represented by objects, h
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ADSetup/CPP/adsetup.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/BaseDirectory/adsetup.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/BaseDirectory/adsetup.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADSetup/VB/adsetup.vb" id="Snippet1":::
]]>
@@ -691,6 +695,7 @@ Application domains, which are represented by objects, h
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ADClearPrivatePath/CPP/adclearprivatepath.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/ClearPrivatePath/adclearprivatepath.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/ClearPrivatePath/adclearprivatepath.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADClearPrivatePath/VB/adclearprivatepath.vb" id="Snippet1":::
]]>
@@ -847,6 +852,7 @@ Application domains, which are represented by objects, h
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_CreateComInstanceFrom/CPP/createcominstancefrom.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/CreateComInstanceFrom/createcominstancefrom.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/CreateComInstanceFrom/createcominstancefrom.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_CreateComInstanceFrom/VB/createcominstancefrom.vb" id="Snippet1":::
]]>
@@ -1030,6 +1036,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_Setup/CPP/setup.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/CreateDomain/setup.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/CreateDomain/setup.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_Setup/VB/setup.vb" id="Snippet1":::
]]>
@@ -1101,6 +1108,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_Setup/CPP/setup.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/CreateDomain/setup.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/CreateDomain/setup.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_Setup/VB/setup.vb" id="Snippet1":::
]]>
@@ -1171,6 +1179,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_Setup/CPP/setup.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/CreateDomain/setup.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/CreateDomain/setup.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_Setup/VB/setup.vb" id="Snippet1":::
]]>
@@ -1319,6 +1328,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_Setup/CPP/setup.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/CreateDomain/setup.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/CreateDomain/setup.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_Setup/VB/setup.vb" id="Snippet1":::
]]>
@@ -1878,6 +1888,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/CreateInstanceAndUnwrap2/cpp/source.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/CreateInstanceAndUnwrap/source.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/source.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/CreateInstanceAndUnwrap2/VB/source.vb" id="Snippet1":::
]]>
@@ -1973,6 +1984,7 @@ This method overload uses the information from the
## Examples
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ADDyno/CPP/addyno.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/CreateInstanceAndUnwrap/addyno.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/addyno.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADDyno/VB/addyno.vb" id="Snippet1":::
]]>
@@ -2079,6 +2091,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_CreateInstance_IgnoreCase/CPP/ignorecase.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/CreateInstanceAndUnwrap/ignorecase.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/ignorecase.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_CreateInstance_IgnoreCase/VB/ignorecase.vb" id="Snippet1":::
]]>
@@ -2187,6 +2200,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_CreateInstance_IgnoreCase/CPP/ignorecase.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/CreateInstanceAndUnwrap/ignorecase.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/ignorecase.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_CreateInstance_IgnoreCase/VB/ignorecase.vb" id="Snippet1":::
]]>
@@ -2315,6 +2329,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.appdomain.createinstancefrom_stringstring/cpp/example.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/CreateInstanceFrom/example.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/CreateInstanceFrom/example.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.appdomain.createinstancefrom_stringstring/vb/example.vb" id="Snippet1":::
]]>
@@ -3101,6 +3116,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ADApplicationBase/CPP/adapplicationbase.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/CurrentDomain/adapplicationbase.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/CurrentDomain/adapplicationbase.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADApplicationBase/VB/adapplicationbase.vb" id="Snippet1":::
]]>
@@ -3183,6 +3199,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_DefineDynamicAssembly/CPP/definedynamicassembly.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/DefineDynamicAssembly/definedynamicassembly.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/DefineDynamicAssembly/definedynamicassembly.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_DefineDynamicAssembly/VB/definedynamicassembly.vb" id="Snippet1":::
]]>
@@ -3263,6 +3280,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/DefineDynamicAssemblyWithAttributes/cpp/source.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/DefineDynamicAssembly/source.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/DefineDynamicAssembly/source.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/DefineDynamicAssemblyWithAttributes/vb/source.vb" id="Snippet1":::
]]>
@@ -3360,6 +3378,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_DefineDynamicAssembly/CPP/definedynamicassembly.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/DefineDynamicAssembly/definedynamicassembly.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/DefineDynamicAssembly/definedynamicassembly.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_DefineDynamicAssembly/VB/definedynamicassembly.vb" id="Snippet1":::
]]>
@@ -3442,6 +3461,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_DefineDynamicAssembly/CPP/definedynamicassembly.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/DefineDynamicAssembly/definedynamicassembly.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/DefineDynamicAssembly/definedynamicassembly.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_DefineDynamicAssembly/VB/definedynamicassembly.vb" id="Snippet1":::
]]>
@@ -3603,6 +3623,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_DefineDynamicAssembly/CPP/definedynamicassembly.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/DefineDynamicAssembly/definedynamicassembly.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/DefineDynamicAssembly/definedynamicassembly.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_DefineDynamicAssembly/VB/definedynamicassembly.vb" id="Snippet1":::
]]>
@@ -3699,6 +3720,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_DefineDynamicAssembly/CPP/definedynamicassembly.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/DefineDynamicAssembly/definedynamicassembly.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/DefineDynamicAssembly/definedynamicassembly.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_DefineDynamicAssembly/VB/definedynamicassembly.vb" id="Snippet1":::
]]>
@@ -3869,6 +3891,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_DefineDynamicAssembly/CPP/definedynamicassembly.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/DefineDynamicAssembly/definedynamicassembly.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/DefineDynamicAssembly/definedynamicassembly.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_DefineDynamicAssembly/VB/definedynamicassembly.vb" id="Snippet1":::
]]>
@@ -3967,6 +3990,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_DefineDynamicAssembly/CPP/definedynamicassembly.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/DefineDynamicAssembly/definedynamicassembly.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/DefineDynamicAssembly/definedynamicassembly.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_DefineDynamicAssembly/VB/definedynamicassembly.vb" id="Snippet1":::
]]>
@@ -4071,6 +4095,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_DefineDynamicAssembly/CPP/definedynamicassembly.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/DefineDynamicAssembly/definedynamicassembly.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/DefineDynamicAssembly/definedynamicassembly.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_DefineDynamicAssembly/VB/definedynamicassembly.vb" id="Snippet1":::
]]>
@@ -4178,6 +4203,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_DefineDynamicAssembly/CPP/definedynamicassembly.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/DefineDynamicAssembly/definedynamicassembly.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/DefineDynamicAssembly/definedynamicassembly.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_DefineDynamicAssembly/VB/definedynamicassembly.vb" id="Snippet1":::
]]>
@@ -4340,18 +4366,21 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_DoCallBack/CPP/docallback_static.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/DoCallBack/docallback_static.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/DoCallBack/docallback_static.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_DoCallBack/VB/docallback_static.vb" id="Snippet1":::
The following sample demonstrates using the method by value.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_DoCallBack/CPP/docallback_byval.cpp" id="Snippet2":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/DoCallBack/docallback_byval.cs" id="Snippet2":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/DoCallBack/docallback_byval.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_DoCallBack/VB/docallback_byval.vb" id="Snippet2":::
The following sample demonstrates using the method by reference.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_DoCallBack/CPP/docallback_byref.cpp" id="Snippet3":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/DoCallBack/docallback_byref.cs" id="Snippet3":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/DoCallBack/docallback_byref.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_DoCallBack/VB/docallback_byref.vb" id="Snippet3":::
]]>
@@ -4550,6 +4579,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ADDynamicBase/CPP/addynamicbase.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/DynamicDirectory/addynamicbase.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/DynamicDirectory/addynamicbase.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADDynamicBase/VB/addynamicbase.vb" id="Snippet1":::
]]>
@@ -4688,6 +4718,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_ExecuteAssembly/CPP/executeassembly.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/ExecuteAssembly/executeassembly.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/ExecuteAssembly/executeassembly.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_ExecuteAssembly/VB/executeassembly.vb" id="Snippet1":::
]]>
@@ -4780,6 +4811,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_ExecuteAssembly/CPP/executeassembly.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/ExecuteAssembly/executeassembly.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/ExecuteAssembly/executeassembly.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_ExecuteAssembly/VB/executeassembly.vb" id="Snippet1":::
]]>
@@ -4869,6 +4901,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_ExecuteAssembly/CPP/executeassembly.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/ExecuteAssembly/executeassembly.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/ExecuteAssembly/executeassembly.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_ExecuteAssembly/VB/executeassembly.vb" id="Snippet1":::
]]>
@@ -4963,6 +4996,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_ExecuteAssembly/CPP/executeassembly.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/ExecuteAssembly/executeassembly.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/ExecuteAssembly/executeassembly.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_ExecuteAssembly/VB/executeassembly.vb" id="Snippet1":::
]]>
@@ -5062,6 +5096,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_ExecuteAssembly/CPP/executeassembly.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/ExecuteAssembly/executeassembly.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/ExecuteAssembly/executeassembly.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_ExecuteAssembly/VB/executeassembly.vb" id="Snippet1":::
]]>
@@ -5154,6 +5189,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_ExecuteAssembly/CPP/executeassembly.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/ExecuteAssembly/executeassembly.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/ExecuteAssembly/executeassembly.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_ExecuteAssembly/VB/executeassembly.vb" id="Snippet1":::
]]>
@@ -5753,6 +5789,7 @@ This method overload uses the information from the
> To see how the stack display grows as the event is raised closer and closer to the default application domain, change `e.Exception.Message` to `e.Exception` in the `FirstChanceHandler` event handlers. Notice that when `TestException` is called across application domain boundaries, it appears twice: once for the proxy and once for the stub.
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/FirstChanceException/example.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/FirstChanceException/example.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.appdomain.firstchanceexception/vb/example.vb" id="Snippet1":::
]]>
@@ -5822,6 +5859,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ADApplicationBase/CPP/adapplicationbase.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/CurrentDomain/adapplicationbase.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/CurrentDomain/adapplicationbase.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADApplicationBase/VB/adapplicationbase.vb" id="Snippet1":::
]]>
@@ -5884,6 +5922,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ADGetAssemblies/CPP/adgetassemblies.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/GetAssemblies/adgetassemblies.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/GetAssemblies/adgetassemblies.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADGetAssemblies/VB/adgetassemblies.vb" id="Snippet1":::
]]>
@@ -6057,6 +6096,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ADGetData/CPP/adgetdata.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/GetData/adgetdata.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/GetData/adgetdata.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADGetData/VB/adgetdata.vb" id="Snippet1":::
]]>
@@ -6162,6 +6202,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.AppDomain.IsDefaultAppDomain/CPP/System.AppDomain.IsDefaultAppDomain.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/Id/source.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/Id/source.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.AppDomain.IsDefaultAppDomain/VB/source.vb" id="Snippet1":::
]]>
@@ -6326,6 +6367,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.AppDomain.IsDefaultAppDomain/CPP/System.AppDomain.IsDefaultAppDomain.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/Id/source.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/Id/source.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.AppDomain.IsDefaultAppDomain/VB/source.vb" id="Snippet1":::
]]>
@@ -6460,6 +6502,7 @@ This method overload uses the information from the
The example creates another `Worker` object in a sandboxed application domain and again calls the `TestIsFullyTrusted` method. Mscorlib is always trusted, even in a partially trusted application domain, but the example assembly is partially trusted.
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/IsFullyTrusted/example.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/IsFullyTrusted/example.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.appdomain.isfullytrusted/vb/example.vb" id="Snippet1":::
]]>
@@ -6605,6 +6648,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_LoadRaw/CPP/loadraw.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/Load/loadraw.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/Load/loadraw.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_LoadRaw/VB/loadraw.vb" id="Snippet1":::
]]>
@@ -6689,6 +6733,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.appdomain.load/cpp/source.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/Load/source.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/Load/source.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.appdomain.load/vb/source.vb" id="Snippet1":::
The assembly is loaded into both domains because does not derive from , and therefore the return value of the method cannot be marshaled. Instead, the common language runtime tries to load the assembly into the calling application domain. The assemblies that are loaded into the two application domains might be different if the path settings for the two application domains are different.
@@ -6870,6 +6915,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_LoadRaw/CPP/loadraw.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/Load/loadraw.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/Load/loadraw.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_LoadRaw/VB/loadraw.vb" id="Snippet1":::
]]>
@@ -7123,6 +7169,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_LoadRaw/CPP/loadraw.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/Load/loadraw.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/Load/loadraw.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_LoadRaw/VB/loadraw.vb" id="Snippet1":::
]]>
@@ -7664,6 +7711,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain.ReflectionOnlyGetAssemblies/CPP/reflectiononly.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/ReflectionOnlyGetAssemblies/reflectiononly.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/ReflectionOnlyGetAssemblies/reflectiononly.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain.ReflectionOnlyGetAssemblies/VB/reflectiononly.vb" id="Snippet1":::
]]>
@@ -7872,6 +7920,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ADSetAppDomainPolicy/CPP/adsetappdomainpolicy.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/SetAppDomainPolicy/adsetappdomainpolicy.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/SetAppDomainPolicy/adsetappdomainpolicy.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADSetAppDomainPolicy/VB/adsetappdomainpolicy.vb" id="Snippet1":::
]]>
@@ -8050,6 +8099,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ADGetData/CPP/adgetdata.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/GetData/adgetdata.cs" interactive="try-dotnet" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/GetData/adgetdata.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADGetData/VB/adgetdata.vb" id="Snippet1":::
]]>
@@ -8195,6 +8245,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ADDynamicBase/CPP/addynamicbase.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/DynamicDirectory/addynamicbase.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/DynamicDirectory/addynamicbase.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADDynamicBase/VB/addynamicbase.vb" id="Snippet1":::
]]>
@@ -8269,6 +8320,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ADPrincipal/CPP/adprincipal.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/SetPrincipalPolicy/adprincipal.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/SetPrincipalPolicy/adprincipal.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADPrincipal/VB/adprincipal.vb" id="Snippet1":::
]]>
@@ -8349,6 +8401,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/adproperties/CPP/adproperties.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/SetShadowCopyFiles/adproperties.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/SetShadowCopyFiles/adproperties.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/adproperties/VB/adproperties.vb" id="Snippet1":::
]]>
@@ -8446,6 +8499,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ADShadowCopy/CPP/adshadowcopy.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/SetShadowCopyPath/adshadowcopy.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/SetShadowCopyPath/adshadowcopy.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADShadowCopy/VB/adshadowcopy.vb" id="Snippet1":::
]]>
@@ -8515,6 +8569,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ADPrincipal/CPP/adprincipal.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/SetPrincipalPolicy/adprincipal.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/SetPrincipalPolicy/adprincipal.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADPrincipal/VB/adprincipal.vb" id="Snippet1":::
]]>
@@ -8885,6 +8940,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ADToString/CPP/adtostring.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/ToString/adtostring.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/ToString/adtostring.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADToString/VB/adtostring.vb" id="Snippet1":::
]]>
@@ -8969,6 +9025,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_TypeResolve/CPP/typeresolve.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/TypeResolve/typeresolve.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/TypeResolve/typeresolve.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_TypeResolve/VB/typeresolve.vb" id="Snippet1":::
]]>
@@ -9073,6 +9130,7 @@ This method overload uses the information from the
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_UnhandledException/CPP/unhandledexception.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/UnhandledException/unhandledexception.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/UnhandledException/unhandledexception.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_UnhandledException/VB/unhandledexception.vb" id="Snippet1":::
]]>
@@ -9155,6 +9213,7 @@ In .NET Framework version 1.0 and 1.1, if the thread that calls
diff --git a/xml/System/AppDomainSetup.xml b/xml/System/AppDomainSetup.xml
index b0d90f3bd6f..68f8c354fa0 100644
--- a/xml/System/AppDomainSetup.xml
+++ b/xml/System/AppDomainSetup.xml
@@ -288,6 +288,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomainInitializer/cpp/source.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomainSetup/AppDomainInitializer/source.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomainSetup/AppDomainInitializer/source.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomainInitializer/VB/source.vb" id="Snippet1":::
]]>
@@ -337,6 +338,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomainInitializer/cpp/source.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomainSetup/AppDomainInitializer/source.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomainSetup/AppDomainInitializer/source.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomainInitializer/VB/source.vb" id="Snippet1":::
]]>
@@ -496,6 +498,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ADApplicationBase/CPP/adapplicationbase.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/CurrentDomain/adapplicationbase.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/CurrentDomain/adapplicationbase.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADApplicationBase/VB/adapplicationbase.vb" id="Snippet1":::
]]>
@@ -546,6 +549,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ADMultiDomain/CPP/admultidomain.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomainSetup/ApplicationName/admultidomain.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomainSetup/ApplicationName/admultidomain.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADMultiDomain/VB/admultidomain.vb" id="Snippet1":::
]]>
@@ -931,6 +935,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ADDynamicBase/CPP/addynamicbase.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/DynamicDirectory/addynamicbase.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/DynamicDirectory/addynamicbase.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADDynamicBase/VB/addynamicbase.vb" id="Snippet1":::
]]>
@@ -1056,6 +1061,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ADDyno/CPP/addyno.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/CreateInstanceAndUnwrap/addyno.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/addyno.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADDyno/VB/addyno.vb" id="Snippet1":::
]]>
diff --git a/xml/System/AppDomainUnloadedException.xml b/xml/System/AppDomainUnloadedException.xml
index a3c3b613b0f..69989f90d95 100644
--- a/xml/System/AppDomainUnloadedException.xml
+++ b/xml/System/AppDomainUnloadedException.xml
@@ -82,6 +82,7 @@
The `TestClass` method is executed without exception handling from a thread and from an ordinary thread, demonstrating that the unhandled exception terminates the task or thread but not the application. It is then executed with and without exception handling from the main application thread, demonstrating that it terminates the application if not handled.
:::code language="csharp" source="~/snippets/csharp/System/AppDomainUnloadedException/Overview/Sample.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomainUnloadedException/Overview/Sample.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomainUnloadedException/vb/Sample.vb" id="Snippet1":::
Example 2
@@ -90,6 +91,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ADUnload/CPP/adunload.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/AppDomain/Unload/adunload.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/Unload/adunload.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADUnload/VB/adunload.vb" id="Snippet1":::
]]>