Skip to content

Commit 564018e

Browse files
committed
NH-3807 - Guard on System.Configuration
1 parent 6bd2cb3 commit 564018e

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

src/NHibernate/Cfg/Configuration.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4-
using System.Configuration;
54
using System.Diagnostics;
65
using System.IO;
76
using System.Linq;
@@ -29,6 +28,10 @@
2928
using NHibernate.Util;
3029
using Array = System.Array;
3130

31+
#if FEATURE_SYSTEM_CONFIGURATION
32+
using System.Configuration;
33+
#endif
34+
3235
#if FEATURE_SERIALIZATION
3336
using System.Runtime.Serialization;
3437
using System.Security;
@@ -1414,12 +1417,14 @@ private void AddProperties(ISessionFactoryConfiguration factoryConfiguration)
14141417
/// </remarks>
14151418
public Configuration Configure()
14161419
{
1420+
#if FEATURE_SYSTEM_CONFIGURATION
14171421
var hc = ConfigurationManager.GetSection(CfgXmlHelper.CfgSectionName) as IHibernateConfiguration;
14181422
if (hc != null && hc.SessionFactory != null)
14191423
{
14201424
return DoConfigure(hc.SessionFactory);
14211425
}
14221426
else
1427+
#endif
14231428
{
14241429
return Configure(GetDefaultConfigurationFilePath());
14251430
}

src/NHibernate/Cfg/ConfigurationSectionHandler.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#if FEATURE_SYSTEM_CONFIGURATION
2+
13
using System;
24
using System.Configuration;
35
using System.Xml;
@@ -19,4 +21,6 @@ object IConfigurationSectionHandler.Create(object parent, object configContext,
1921

2022
#endregion
2123
}
22-
}
24+
}
25+
26+
#endif

src/NHibernate/Cfg/Environment.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Configuration;
43
using System.Linq;
54
using System.Reflection;
65

76
using NHibernate.Bytecode;
87
using NHibernate.Cfg.ConfigurationSchema;
98
using NHibernate.Util;
109

10+
#if FEATURE_SYSTEM_CONFIGURATION
11+
using System.Configuration;
12+
#endif
13+
1114
namespace NHibernate.Cfg
1215
{
1316
/// <summary>
@@ -233,6 +236,7 @@ static Environment()
233236

234237
private static void LoadGlobalPropertiesFromAppConfig()
235238
{
239+
#if FEATURE_SYSTEM_CONFIGURATION
236240
object config = ConfigurationManager.GetSection(CfgXmlHelper.CfgSectionName);
237241

238242
if (config == null)
@@ -260,6 +264,7 @@ private static void LoadGlobalPropertiesFromAppConfig()
260264
GlobalProperties[kvp.Key] = kvp.Value;
261265
}
262266
}
267+
#endif
263268
}
264269

265270
internal static void ResetSessionFactoryProperties()

src/NHibernate/Connection/ConnectionProvider.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
using System;
22
using System.Collections;
3-
using System.Configuration;
43
using System.Data.Common;
54

65
using NHibernate.Driver;
76
using NHibernate.Util;
87
using Environment=NHibernate.Cfg.Environment;
98
using System.Collections.Generic;
109

10+
#if FEATURE_SYSTEM_CONFIGURATION
11+
using System.Configuration;
12+
#endif
13+
1114
namespace NHibernate.Connection
1215
{
1316
/// <summary>
@@ -73,6 +76,7 @@ public virtual void Configure(IDictionary<string, string> settings)
7376
/// </exception>
7477
protected virtual string GetNamedConnectionString(IDictionary<string, string> settings)
7578
{
79+
#if FEATURE_SYSTEM_CONFIGURATION
7680
string connStringName;
7781
if(!settings.TryGetValue(Environment.ConnectionStringName, out connStringName))
7882
return null;
@@ -81,6 +85,9 @@ protected virtual string GetNamedConnectionString(IDictionary<string, string> se
8185
if (connectionStringSettings == null)
8286
throw new HibernateException(string.Format("Could not find named connection string {0}", connStringName));
8387
return connectionStringSettings.ConnectionString;
88+
#else
89+
return null;
90+
#endif
8491
}
8592

8693
/// <summary>

src/NHibernate/Logging.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
using System;
2-
using System.Configuration;
32
using System.IO;
43
using System.Linq;
54
using System.Linq.Expressions;
65
using System.Reflection;
76
using NHibernate.Util;
87

8+
#if FEATURE_SYSTEM_CONFIGURATION
9+
using System.Configuration;
10+
#endif
11+
912
namespace NHibernate
1013
{
1114
public interface IInternalLogger
@@ -79,9 +82,11 @@ private static ILoggerFactory GetLoggerFactory(string nhibernateLoggerClass)
7982

8083
private static string GetNhibernateLoggerClass()
8184
{
82-
var nhibernateLogger = ConfigurationManager.AppSettings.Keys.Cast<string>().FirstOrDefault(k => NhibernateLoggerConfKey.Equals(k.ToLowerInvariant()));
8385
string nhibernateLoggerClass = null;
86+
#if FEATURE_SYSTEM_CONFIGURATION
87+
var nhibernateLogger = ConfigurationManager.AppSettings.Keys.Cast<string>().FirstOrDefault(k => NhibernateLoggerConfKey.Equals(k.ToLowerInvariant()));
8488
if (string.IsNullOrEmpty(nhibernateLogger))
89+
#endif
8590
{
8691
// look for log4net.dll
8792
string baseDir = AppDomain.CurrentDomain.BaseDirectory;
@@ -94,10 +99,12 @@ private static string GetNhibernateLoggerClass()
9499
nhibernateLoggerClass = typeof (Log4NetLoggerFactory).AssemblyQualifiedName;
95100
}
96101
}
102+
#if FEATURE_SYSTEM_CONFIGURATION
97103
else
98104
{
99105
nhibernateLoggerClass = ConfigurationManager.AppSettings[nhibernateLogger];
100106
}
107+
#endif
101108
return nhibernateLoggerClass;
102109
}
103110

0 commit comments

Comments
 (0)