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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<linker>
<assembly fullname="System.Configuration.ConfigurationManager">
<type fullname="System.Configuration.ConfigurationManager">
<method signature="System.Boolean get_DisableConfigurationManager()" body="stub" value="true" feature="Switch.System.Configuration.ConfigurationManager.DisableConfigurationManager" featurevalue="true" />
</type>
</assembly>
</linker>
Original file line number Diff line number Diff line change
Expand Up @@ -694,4 +694,7 @@
<data name="TL_InitializeData_NotSpecified" xml:space="preserve">
<value>initializeData needs to be valid for this TraceListener.</value>
</data>
<data name="ConfigurationManagerDisabled" xml:space="preserve">
<value>Working with ConfigurationManager is disabled.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<IsPartialFacadeAssembly Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETFramework'">true</IsPartialFacadeAssembly>
</PropertyGroup>

<ItemGroup>
<ILLinkSubstitutionsXmls Include="$(ILLinkDirectory)ILLink.Substitutions.xml" />
</ItemGroup>

<ItemGroup Condition="'$(IsPartialFacadeAssembly)' != 'true'">
<Compile Include="System\Configuration\DictionarySectionHandler.cs" />
<Compile Include="System\Configuration\DpapiProtectedConfigurationProvider.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ private static void PrepareConfigSystem()

public static object GetSection(string sectionName)
{
if (DisableConfigurationManager)
return null;

// Avoid unintended AV's by ensuring sectionName is not empty.
// For compatibility, we cannot throw an InvalidArgumentException.
if (string.IsNullOrEmpty(sectionName)) return null;
Expand All @@ -157,6 +160,9 @@ public static object GetSection(string sectionName)

public static void RefreshSection(string sectionName)
{
if (DisableConfigurationManager)
return;

// Avoid unintended AV's by ensuring sectionName is not empty.
// For consistency with GetSection, we should not throw an InvalidArgumentException.
if (string.IsNullOrEmpty(sectionName)) return;
Expand Down Expand Up @@ -201,6 +207,9 @@ public static Configuration OpenMappedExeConfiguration(ExeConfigurationFileMap f
private static Configuration OpenExeConfigurationImpl(ConfigurationFileMap fileMap, bool isMachine,
ConfigurationUserLevel userLevel, string exePath, bool preLoad = false)
{
if (DisableConfigurationManager)
throw new ArgumentException(SR.ConfigurationManagerDisabled);

// exePath must be specified if not running inside ClientConfigurationSystem
if (!isMachine &&
(((fileMap == null) && (exePath == null)) ||
Expand Down Expand Up @@ -243,6 +252,15 @@ private static void PreloadConfigurationSectionGroup(ConfigurationSectionGroup s
PreloadConfigurationSectionGroup(childSectionGroup);
}

private static bool s_disableConfigurationManager;
private static bool DisableConfigurationManager
{
get
{
return AppContext.TryGetSwitch(@"System.Configuration.ConfigurationManager.DisableConfigurationManager", out s_disableConfigurationManager) ? s_disableConfigurationManager : false;
}
}

private enum InitState
{
// Initialization has not yet started.
Expand Down