Open SamLowryMOI opened 1 year ago
Thanks @SamLowryMOI sounds like the workaround is to use PowerShell 7, this looks like an issue with the GAC
looks like an issue with the GAC
I don't think so, the GAC is the same for all programmes, isn't it?
I compared which Powershell 5.1 assemblies are loaded in the Windows console and the VS Code Terminal.
These dlls are loaded by both:
GlobalAssemblyCache FullName
------------------- --------
False Anonymously Hosted DynamicMethods Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
True Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
True Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
True Microsoft.PowerShell.Commands.Utility, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
True Microsoft.PowerShell.ConsoleHost, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
True Microsoft.PowerShell.ConsoleHost.resources, Version=3.0.0.0, Culture=de, PublicKeyToken=31bf3856ad364e35
True Microsoft.PowerShell.Security, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
True mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
True mscorlib.resources, Version=4.0.0.0, Culture=de, PublicKeyToken=b77a5c561934e089
True System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
True System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
True System.Configuration.Install, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
True System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
True System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
True System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
True System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
True System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
True System.Management.Automation.resources, Version=3.0.0.0, Culture=de, PublicKeyToken=31bf3856ad364e35
True System.Numerics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
True System.Transactions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
True System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
This dll is only loaded by the Windows console:
GlobalAssemblyCache FullName
------------------- --------
False Microsoft.Powershell.PSReadline, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
These dlls are only loaded by the VS Code Terminal:
GlobalAssemblyCache FullName
------------------- --------
False MediatR, Version=8.0.0.0, Culture=neutral, PublicKeyToken=bb9a41a5e8aaa7e2
False Microsoft.Extensions.Configuration, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
False Microsoft.Extensions.Configuration.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
False Microsoft.Extensions.DependencyInjection.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
False Microsoft.Extensions.Logging, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
False Microsoft.Extensions.Logging.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
False Microsoft.Extensions.Options, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
False Microsoft.Extensions.Primitives, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
False Microsoft.PowerShell.CrossCompatibility, Version=1.21.0.0, Culture=neutral, PublicKeyToken=null
False Microsoft.PowerShell.EditorServices, Version=3.8.1.0, Culture=neutral, PublicKeyToken=null
False Microsoft.PowerShell.EditorServices.Hosting, Version=3.8.1.0, Culture=neutral, PublicKeyToken=null
False Microsoft.PowerShell.EditorServices.VSCode, Version=3.8.1.0, Culture=neutral, PublicKeyToken=null
False Microsoft.PowerShell.PSReadLine.Polyfiller, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
False Microsoft.PowerShell.PSReadLine2, Version=2.2.6.0, Culture=neutral, PublicKeyToken=null
False Microsoft.VisualStudio.Threading, Version=16.10.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
False Microsoft.VisualStudio.Validation, Version=16.10.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
False Microsoft.Windows.PowerShell.ScriptAnalyzer, Version=1.21.0.0, Culture=neutral, PublicKeyToken=null
False Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules, Version=1.21.0.0, Culture=neutral, PublicKeyToken=null
False Nerdbank.Streams, Version=2.8.0.0, Culture=neutral, PublicKeyToken=cac503e1823ce71c
False Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
False Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
False OmniSharp.Extensions.DebugAdapter, Version=0.19.0.0, Culture=neutral, PublicKeyToken=6d868dff454e6022
False OmniSharp.Extensions.DebugAdapter.Server, Version=0.19.0.0, Culture=neutral, PublicKeyToken=6d868dff454e6022
False OmniSharp.Extensions.JsonRpc, Version=0.19.0.0, Culture=neutral, PublicKeyToken=6d868dff454e6022
False OmniSharp.Extensions.LanguageProtocol, Version=0.19.0.0, Culture=neutral, PublicKeyToken=6d868dff454e6022
False OmniSharp.Extensions.LanguageServer, Version=0.19.0.0, Culture=neutral, PublicKeyToken=6d868dff454e6022
False OmniSharp.Extensions.LanguageServer.Shared, Version=0.19.0.0, Culture=neutral, PublicKeyToken=6d868dff454e6022
False Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10
False Serilog.Extensions.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10
False Serilog.Sinks.Async, Version=1.5.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10
False Serilog.Sinks.File, Version=5.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10
False System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
False System.Collections.Immutable, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
False System.IO.Pipelines, Version=5.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
False System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
False System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
False System.Reactive, Version=5.0.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263
False System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
False System.Threading.Channels, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
False System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
True Microsoft.PowerShell.Commands.Diagnostics, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
True Microsoft.PowerShell.Commands.Management, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
True Microsoft.PowerShell.Commands.Utility.resources, Version=3.0.0.0, Culture=de, PublicKeyToken=31bf3856ad364e35
True Microsoft.PowerShell.Security.resources, Version=3.0.0.0, Culture=de, PublicKeyToken=31bf3856ad364e35
True Microsoft.WSMan.Management, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
True Microsoft.WSMan.Management.resources, Version=3.0.0.0, Culture=de, PublicKeyToken=31bf3856ad364e35
True netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
True System.ComponentModel.Composition, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
True System.Dynamic, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
True System.Reflection.Emit.ILGeneration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
True System.Reflection.Emit.Lightweight, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
True System.resources, Version=4.0.0.0, Culture=de, PublicKeyToken=b77a5c561934e089
True System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
True System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
True System.ValueTuple, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
True System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
True System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
You can see that the VS Code Terminal loads 57 dlls in addition.
I don't know the tasks of the additional dlls, but labels like
False Microsoft.VisualStudio.Validation, Version=16.10.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
False Microsoft.Windows.PowerShell.ScriptAnalyzer, Version=1.21.0.0, Culture=neutral, PublicKeyToken=null
False Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules, Version=1.21.0.0, Culture=neutral, PublicKeyToken=null
lead me to believe that the VS Code Terminal performs additional checks and, in contrast to the Windows console, makes a distinction between classes and interfaces.
But unfortunately, there is no way around this, as Powershell does not make a difference despite the correct declaration.
And as workarounds, I run the script in VS Code with the extension "Run in Powershell" and debug in Powershell ISE.
What Sydney means is that, since Windows PowerShell 5.1 uses the .NET Framework, it has to use the GAC for assembly resolution instead of an Assembly Load Context (as available in PowerShell Core 7.x because it's built on .NET Core). This means that when using 5.1, the dependencies of the extension (the module PowerShell Editor Services and its dependencies, as you listed out) are not able to be isolated, thus leading to this problem where it works in a non-Extension Terminal, and it works in an Extension Terminal when using 7.x.
@andschwa This explains why the terminal loads the additional dlls, but not why the error occurs.
Loading a dll and using it are different things, aren't they?
If it is necessary to use a specific debugger that recognises the difference between OptionsMonitor and IOptionsMonitor because of the limitations you mentioned, ok.
But the error still occurs primarily because of the debugger. Or not?
I would just like to understand it.
Prerequisites
Summary
I have had these casting problems several times. Now I am taking the time to document them. They were always error messages like "Type A cannot be converted to type A". But only in the Windows Powershell 5.1 terminal.
Also, the example script below in "Steps to Reproduce" does not work in the Windows Powershell 5.1 terminal only.
Expected:
But I get this:
The crucial error is:
Why does this happen and how can I avoid it?
I know that one type is an interface. But for one thing, Powershell doesn't know the difference. On the other hand, why does it work in a Windows Powershell 5.1 console, but not in the Windows Powershell 5.1 terminal of VS Code?
PowerShell Version
Visual Studio Code Version
Extension Version
Steps to Reproduce
Visuals
No response
Logs
No response