Skip to content

Commit c16eef3

Browse files
committed
NH-3807 - Since AppDomain is no longer CoreClr, use AppContext.BaseDirectory instead of AppDomain.CurrentDomain.BaseDirectory.
Added shim for easier use with .NET 4.0.
1 parent 623ba7b commit c16eef3

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

src/NHibernate/Cfg/Configuration.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,10 +1862,15 @@ private void ValidationHandler(object o, ValidationEventArgs args)
18621862

18631863
protected virtual string GetDefaultConfigurationFilePath()
18641864
{
1865+
#if FEATURE_APPDOMAIN
18651866
string baseDir = AppDomain.CurrentDomain.BaseDirectory;
18661867

18671868
// Note RelativeSearchPath can be null even if the doc say something else; don't remove the check
18681869
var searchPath = AppDomain.CurrentDomain.RelativeSearchPath ?? string.Empty;
1870+
#else
1871+
string baseDir = AppContext.BaseDirectory;
1872+
var searchPath = string.Empty;
1873+
#endif
18691874

18701875
string relativeSearchPath = searchPath.Split(';').First();
18711876
string binPath = Path.Combine(baseDir, relativeSearchPath);

src/NHibernate/Compat/AppContext.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#if NET_4_0
2+
namespace System
3+
{
4+
internal static class AppContext
5+
{
6+
/// <summary>Gets the pathname of the base directory that the assembly resolver uses to probe for assemblies. </summary>
7+
public static string BaseDirectory
8+
{
9+
get { return AppDomain.CurrentDomain.BaseDirectory; }
10+
}
11+
}
12+
}
13+
#endif

src/NHibernate/Logging.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,21 @@ private static string GetNhibernateLoggerClass()
8989
#endif
9090
{
9191
// look for log4net.dll
92+
#if FEATURE_APPDOMAIN
9293
string baseDir = AppDomain.CurrentDomain.BaseDirectory;
9394
string relativeSearchPath = AppDomain.CurrentDomain.RelativeSearchPath;
95+
#else
96+
string baseDir = AppContext.BaseDirectory;
97+
string relativeSearchPath = null;
98+
#endif
9499
string binPath = relativeSearchPath == null ? baseDir : Path.Combine(baseDir, relativeSearchPath);
95100
string log4NetDllPath = binPath == null ? "log4net.dll" : Path.Combine(binPath, "log4net.dll");
96101

97-
if (File.Exists(log4NetDllPath) || AppDomain.CurrentDomain.GetAssemblies().Any(a => a.GetName().Name == "log4net"))
102+
if (File.Exists(log4NetDllPath)
103+
#if FEATURE_APPDOMAIN
104+
|| AppDomain.CurrentDomain.GetAssemblies().Any(a => a.GetName().Name == "log4net")
105+
#endif
106+
)
98107
{
99108
nhibernateLoggerClass = typeof (Log4NetLoggerFactory).AssemblyQualifiedName;
100109
}

src/NHibernate/Mapping/ByCode/MappingsExtensions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,13 @@ public static string AsString(this HbmMapping mappings)
4040

4141
private static string ArrangeMappingsFolderPath()
4242
{
43+
#if FEATURE_APPDOMAIN
4344
string baseDir = AppDomain.CurrentDomain.BaseDirectory;
4445
string relativeSearchPath = AppDomain.CurrentDomain.RelativeSearchPath;
46+
#else
47+
string baseDir = AppContext.BaseDirectory;
48+
string relativeSearchPath = null;
49+
#endif
4550
string binPath = relativeSearchPath != null ? Path.Combine(baseDir, relativeSearchPath): baseDir;
4651
string mappingsFolderPath = Path.Combine(binPath, "Mappings");
4752

src/NHibernate/NHibernate.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
<Compile Include="Collection\IPersistentCollection.cs" />
149149
<Compile Include="Collection\Generic\SetHelpers\ISetSnapshot.cs" />
150150
<Compile Include="Collection\Generic\SetHelpers\SetSnapShot.cs" />
151+
<Compile Include="Compat\AppContext.cs" />
151152
<Compile Include="Compat\CustomAttributeExtensions.cs" />
152153
<Compile Include="Compat\DesignerCategoryAttribute.cs" />
153154
<Compile Include="Compat\ICloneable.cs" />

0 commit comments

Comments
 (0)