Skip to content

Commit c06b280

Browse files
committed
DNET-788
1 parent fafc19a commit c06b280

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnectionInternal.cs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using System.IO;
2424
using System.Reflection;
2525
using FirebirdSql.Data.Common;
26+
using System.Linq;
2627
#if !NETSTANDARD1_6
2728
using FirebirdSql.Data.Schema;
2829
#endif
@@ -457,42 +458,38 @@ private DatabaseParameterBuffer BuildDpb(IDatabase db, FbConnectionString option
457458

458459
private string GetProcessName()
459460
{
460-
// showing ApplicationPhysicalPath may be wrong because of connection pooling; better idea?
461-
return GetHostingPath() ?? GetRealProcessName();
461+
return GetSystemWebHostingPath() ?? GetRealProcessName() ?? string.Empty;
462462
}
463463

464464

465-
private string GetHostingPath()
465+
private string GetSystemWebHostingPath()
466466
{
467467
#if NETSTANDARD1_6 || NETSTANDARD2_0
468-
return System.AppContext.BaseDirectory;
468+
return null;
469469
#else
470-
Assembly assembly;
471-
try
472-
{
473-
assembly = Assembly.Load(string.Format("System.Web, Version={0}.{1}.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", Environment.Version.Major, Environment.Version.Minor));
474-
}
475-
catch (FileNotFoundException)
476-
{
477-
return null;
478-
}
479-
catch (FileLoadException)
480-
{
481-
return null;
482-
}
483-
catch (BadImageFormatException)
484-
{
470+
var assembly = AppDomain.CurrentDomain.GetAssemblies().Where(x => x.GetName().Name.Equals("System.Web", StringComparison.Ordinal)).FirstOrDefault();
471+
if (assembly == null)
485472
return null;
486-
}
487-
return (string)assembly
488-
.GetType("System.Web.Hosting.HostingEnvironment")
489-
.GetProperty("ApplicationPhysicalPath")
490-
.GetValue(null, null);
473+
// showing ApplicationPhysicalPath may be wrong because of connection pooling
474+
// better idea?
475+
return (string)assembly.GetType("System.Web.Hosting.HostingEnvironment").GetProperty("ApplicationPhysicalPath").GetValue(null, null);
491476
#endif
492477
}
478+
493479
private string GetRealProcessName()
494480
{
495-
return Assembly.GetEntryAssembly()?.Location ?? Process.GetCurrentProcess().MainModule.FileName;
481+
string FromProcess()
482+
{
483+
try
484+
{
485+
return Process.GetCurrentProcess().MainModule.FileName;
486+
}
487+
catch (InvalidOperationException)
488+
{
489+
return null;
490+
}
491+
}
492+
return Assembly.GetEntryAssembly()?.Location ?? FromProcess();
496493
}
497494

498495
private int GetProcessId()

0 commit comments

Comments
 (0)