Просмотр исходного кода

Issue 2338 – Session.DebugLogPath cannot be set in single-file bundles

https://winscp.net/tracker/2338

Source commit: 95f66bc1eee542691a29ae912d413f104f16ab10
Martin Prikryl 9 месяцев назад
Родитель
Сommit
9592a02d22
1 измененных файлов с 26 добавлено и 9 удалено
  1. 26 9
      dotnet/internal/Logger.cs

+ 26 - 9
dotnet/internal/Logger.cs

@@ -29,6 +29,23 @@ namespace WinSCP
             return (assembly != null) ? DoGetAssemblyFilePath(assembly) : null;
         }
 
+        private string TryGetCodeBase(Assembly assembly, out Exception e)
+        {
+            string result;
+            try
+            {
+                e = null;
+                result = assembly.CodeBase;
+            }
+            // CodeBase is not supported on assemblies loaded from a single-file bundle
+            catch (NotSupportedException ex)
+            {
+                e = ex;
+                result = null;
+            }
+            return result;
+        }
+
         private string DoGetAssemblyFilePath(Assembly assembly)
         {
             string path = null;
@@ -42,15 +59,13 @@ namespace WinSCP
 
             // It's also good to know that the CodeBase is not guaranteed to be set for assemblies in the GAC.
             // Location will always be set for assemblies loaded from disk, however.
-            string codeBase;
-            try
-            {
-                codeBase = assembly.CodeBase;
-            }
-            catch (NotSupportedException e)
+            string codeBase = TryGetCodeBase(assembly, out Exception e);
+            if (codeBase == null)
             {
-                // CodeBase is not supported on assemblies loaded from a single-file bundle
-                WriteLine($"CodeBase not supported: {e.Message}");
+                if (e != null)
+                {
+                    WriteLine($"CodeBase not supported: {e.Message}");
+                }
                 codeBase = string.Empty;
             }
 
@@ -368,7 +383,9 @@ namespace WinSCP
             WriteLine(".NET Framework build");
 #endif
             WriteLine("Executing assembly: {0}", assembly);
-            WriteLine("Executing assembly codebase: {0}", (assembly.CodeBase ?? "unknown"));
+            string codeBase =
+                TryGetCodeBase(assembly, out Exception e) ?? e?.Message ?? "unknown";
+            WriteLine("Executing assembly codebase: {0}", codeBase);
             WriteLine("Executing assembly location: {0}", (assembly.Location ?? "unknown"));
             Assembly entryAssembly = Assembly.GetEntryAssembly();
             WriteLine("Entry Assembly: {0}", (entryAssembly != null ? entryAssembly.ToString() : "unmanaged"));