|
23 | 23 | using System.IO; |
24 | 24 | using System.Reflection; |
25 | 25 | using FirebirdSql.Data.Common; |
| 26 | +using System.Linq; |
26 | 27 | #if !NETSTANDARD1_6 |
27 | 28 | using FirebirdSql.Data.Schema; |
28 | 29 | #endif |
@@ -457,42 +458,38 @@ private DatabaseParameterBuffer BuildDpb(IDatabase db, FbConnectionString option |
457 | 458 |
|
458 | 459 | private string GetProcessName() |
459 | 460 | { |
460 | | - // showing ApplicationPhysicalPath may be wrong because of connection pooling; better idea? |
461 | | - return GetHostingPath() ?? GetRealProcessName(); |
| 461 | + return GetSystemWebHostingPath() ?? GetRealProcessName() ?? string.Empty; |
462 | 462 | } |
463 | 463 |
|
464 | 464 |
|
465 | | - private string GetHostingPath() |
| 465 | + private string GetSystemWebHostingPath() |
466 | 466 | { |
467 | 467 | #if NETSTANDARD1_6 || NETSTANDARD2_0 |
468 | | - return System.AppContext.BaseDirectory; |
| 468 | + return null; |
469 | 469 | #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) |
485 | 472 | 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); |
491 | 476 | #endif |
492 | 477 | } |
| 478 | + |
493 | 479 | private string GetRealProcessName() |
494 | 480 | { |
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(); |
496 | 493 | } |
497 | 494 |
|
498 | 495 | private int GetProcessId() |
|
0 commit comments