Skip to content

Commit 795f914

Browse files
committed
Add host option to disable AssemblyLoadContext
A host can disable the use of AssemblyLoadContext by returning a value of "true" or "1" when GetHostOption is called with the option name "DisableAssemblyLoadContext". This is an escape hatch for hosts that have issues with the ALC behavior, allowing them to opt out until the underlying issues can be fixed.
1 parent 6ec6c31 commit 795f914

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Mono.TextTemplating/Mono.TextTemplating/CompiledTemplate.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ TemplateProcessor CreateTemplateProcessor ()
8585

8686
// hosts are supposed to return null of they don't want to use a domain
8787
// but check for CurrentDomain too so we can optimize if they do that
88-
if (domain == null || domain == AppDomain.CurrentDomain) {
88+
if (domain == null || domain == AppDomain.CurrentDomain
89+
#if FEATURE_ASSEMBLY_LOAD_CONTEXT
90+
|| host.IsAssemblyLoadContextDisabled ()
91+
#endif
92+
) {
8993
return new TemplateProcessor ();
9094
}
9195

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using Microsoft.VisualStudio.TextTemplating;
6+
7+
static class HostOptionExtensions
8+
{
9+
const string DisableAlcOptionName = "DisableAssemblyLoadContext";
10+
11+
static bool IsOptionTrue (this ITextTemplatingEngineHost host, string optionName) =>
12+
host.GetHostOption(optionName) is string optionVal
13+
&& (optionVal == "1" || optionVal.Equals("true", StringComparison.OrdinalIgnoreCase));
14+
15+
public static bool IsAssemblyLoadContextDisabled (this ITextTemplatingEngineHost host) => host.IsOptionTrue (DisableAlcOptionName);
16+
}

0 commit comments

Comments
 (0)