Skip to content

Add stack trace to resolve event handler on debug #1527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
Expand Down Expand Up @@ -93,7 +94,11 @@ public static EditorServicesLoader Create(

AssemblyLoadContext.Default.Resolving += (AssemblyLoadContext defaultLoadContext, AssemblyName asmName) =>
{
#if DEBUG
logger.Log(PsesLogLevel.Diagnostic, $"Assembly resolve event fired for {asmName}. Stacktrace:\n{new StackTrace()}");
#else
logger.Log(PsesLogLevel.Diagnostic, $"Assembly resolve event fired for {asmName}");
#endif

// We only want the Editor Services DLL; the new ALC will lazily load its dependencies automatically
if (!string.Equals(asmName.Name, "Microsoft.PowerShell.EditorServices", StringComparison.Ordinal))
Expand Down Expand Up @@ -124,7 +129,11 @@ public static EditorServicesLoader Create(
// Unlike in .NET Core, we need to be look for all dependencies in .NET Framework, not just PSES.dll
AppDomain.CurrentDomain.AssemblyResolve += (object sender, ResolveEventArgs args) =>
{
#if DEBUG
logger.Log(PsesLogLevel.Diagnostic, $"Assembly resolve event fired for {args.Name}. Stacktrace:\n{new StackTrace()}");
#else
logger.Log(PsesLogLevel.Diagnostic, $"Assembly resolve event fired for {args.Name}");
#endif

var asmName = new AssemblyName(args.Name);
var dllName = $"{asmName.Name}.dll";
Expand Down