question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dependencies erroneously loaded from GAC first in Windows PowerShell

See original GitHub issue

Issue Description

Powershell services appears to crash on launch with ‘Missing method exception:’

Exception calling "StartLogging" with "2" argument(s): "Method not found: 'Serilog.LoggerConfiguration Serilog.Configuration.LoggerSinkConfiguration.Wrap(Serilog.Configuration.LoggerSinkConfiguration, System.Func`2<Serilog.Core.ILogEventSink,Serilog.Core.ILogEventSink>, System.Action`1<Serilog.Configuration.LoggerSinkConfiguration>, Serilog.Events.LogEventLevel, Serilog.Core.LoggingLevelSwitch)'."
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
   at System.Management.Automation.PSScriptCmdlet.RunClause(Action`1 clause, Object dollarUnderbar, Object inputToProcess)
   at System.Management.Automation.PSScriptCmdlet.DoEndProcessing()
   at System.Management.Automation.CommandProcessorBase.Complete()
Method not found: 'Serilog.LoggerConfiguration Serilog.Configuration.LoggerSinkConfiguration.Wrap(Serilog.Configuration.LoggerSinkConfiguration, System.Func`2<Serilog.Core.ILogEventSink,Serilog.Core.ILogEventSink>, System.Action`1<Serilog.Configuration.LoggerSinkConfiguration>, Serilog.Events.LogEventLevel, Serilog.Core.LoggingLevelSwitch)'.
   at Serilog.LoggerConfigurationAsyncExtensions.Async(LoggerSinkConfiguration loggerSinkConfiguration, Action`1 configure, IAsyncLogEventSinkMonitor monitor, Int32 bufferSize, Boolean blockWhenFull)
   at Microsoft.PowerShell.EditorServices.Utility.Logging.Builder.Build()
   at Microsoft.PowerShell.EditorServices.Host.EditorServicesHost.StartLogging(String logFilePath, LogLevel logLevel)
   at CallSite.Target(Closure , CallSite , Object , Object , Object )

Attached Logs

Powershell-logs.zip

Environment Information

Visual Studio Code

Name Version
Operating System Windows_NT x64 10.0.17763
VSCode 1.36.1
PowerShell Extension Version 2019.5.0

PowerShell Information

Name Value
PSVersion 5.1.17763.316
PSEdition Desktop
PSCompatibleVersions 1.0 2.0 3.0 4.0 5.0 5.1.17763.316
BuildVersion 10.0.17763.316
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Visual Studio Code Extensions

Visual Studio Code Extensions(Click to Expand)
Extension Author Version
csharp ms-vscode 1.21.0
gitblame waderyan 2.8.1
powershell ms-vscode 2019.5.0
prettier-vscode esbenp 1.9.0
tslint eg2 1.0.44
vscode-antlr4 mike-lischke 2.1.1
vsliveshare ms-vsliveshare 1.0.540

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
rjmholtcommented, Jun 9, 2021

I know this is the older issue, but https://github.com/PowerShell/vscode-powershell/issues/2538 has some more pertinent discussion so I’ll deduplicate to that and pin that one.

Loading from the GAC first is a by-design behaviour in .NET Framework that we can’t work around and the issue is that Serilog’s assembly versioning is deliberately broken.

The solution for us is likely to remove Serilog.

1reaction
rjmholtcommented, Jul 25, 2019

Ah nice hunch! It’s a bug on our part then; we only add the types we immediately call into on startup and let them load their dependencies as they go. From this it sounds like that’s fragile and we should eagerly load everything (although in PS 6+ this isn’t a problem actually)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolving PowerShell module assembly dependency conflicts
PowerShell always loads assemblies into the same context. This presents issues when a module's dependencies conflict with already-loaded ...
Read more >
Basics: When does a .NET Assembly Dependency get loaded
Specifically ASP.NET pre-loads all assemblies referenced in the GAC assembly list and the /bin folder. So in Web applications it definitely pays ...
Read more >
Telerik Web Forms Using the Global Assembly Cache
If you get the "Could not load file or assembly…" error. It means the reference is typed in wrongly or the assembly is...
Read more >
c# - PowerShell: why am I able to load multiple versions of the ...
In your scenario, your modules are stand-alone .NET assemblies that implement PowerShell cmdlets. In both Windows PowerShell and PowerShell ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found