PowerShell / vscode-powershell

Provides PowerShell language and debugging support for Visual Studio Code
https://marketplace.visualstudio.com/items/ms-vscode.PowerShell
MIT License
1.72k stars 492 forks source link

Suggestions for parameter types not working #2908

Open PrzemyslawKlys opened 4 years ago

PrzemyslawKlys commented 4 years ago

Issue Description

I am experiencing a problem with... not being given parameter types. It works, works, works and randomly stops.

image

I had this problem before and it was solved in: https://github.com/PowerShell/vscode-powershell/issues/2743 by @SeeminglyScience pointing to a module problem. The difference being it didn't work at all back then, but now it's working fine just simply fails after a while.

I've used the same debug steps as in other thread and this time it's not about problems with that external helper module but some problems with DLL.

Is there anything I can do?

1598194129-afdfd4de-6452-4c44-a771-59ce3569b53b1598107482495.zip

TabExpansion2 -inputScript ($s = '[IDictionary') -cursorColumn $s.Length                      

Exception calling "CompleteInput" with "3" argument(s): "Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information."
At line:38 char:16
+ ...      return [System.Management.Automation.CommandCompletion]::Complet ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ReflectionTypeLoadException
$e = $Error[0].Exception
while ($e -and $null -eq $e.LoaderExceptions) {
    $e = $e.InnerException
}

$e.LoaderExceptions | fl * -for

Message        : Could not load file or assembly 'Microsoft.Data.Services.Client, Version=5.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
FileName       : Microsoft.Data.Services.Client, Version=5.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
FusionLog      : WRN: Assembly binding logging is turned OFF.
                 To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
                 Note: There is some performance penalty associated with assembly bind failure logging.
                 To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Data           : {}
InnerException :
TargetSite     :
StackTrace     :
HelpLink       :
Source         :
HResult        : -2147024894

Message        : Could not load file or assembly 'Microsoft.Data.Services.Client, Version=5.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
FileName       : Microsoft.Data.Services.Client, Version=5.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
FusionLog      : WRN: Assembly binding logging is turned OFF.
                 To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
                 Note: There is some performance penalty associated with assembly bind failure logging.
                 To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Data           : {}
InnerException :
TargetSite     :
StackTrace     :
HelpLink       :
Source         :
HResult        : -2147024894

Message        : Could not load file or assembly 'Microsoft.Data.Services.Client, Version=5.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
FileName       : Microsoft.Data.Services.Client, Version=5.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
FusionLog      : WRN: Assembly binding logging is turned OFF.
                 To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
                 Note: There is some performance penalty associated with assembly bind failure logging.
                 To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Data           : {}
InnerException :
TargetSite     :
StackTrace     :
HelpLink       :
Source         :
HResult        : -2147024894

Message        : Could not load file or assembly 'Microsoft.Data.Services.Client, Version=5.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
FileName       : Microsoft.Data.Services.Client, Version=5.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
FusionLog      : WRN: Assembly binding logging is turned OFF.
                 To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
                 Note: There is some performance penalty associated with assembly bind failure logging.
                 To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Data           : {}
InnerException :
TargetSite     :
StackTrace     :
HelpLink       :
Source         :
HResult        : -2147024894

Message        : Could not load file or assembly 'Microsoft.Data.Services.Client, Version=5.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
FileName       : Microsoft.Data.Services.Client, Version=5.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
FusionLog      : WRN: Assembly binding logging is turned OFF.
                 To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
                 Note: There is some performance penalty associated with assembly bind failure logging.
                 To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Data           : {}
InnerException :
TargetSite     :
StackTrace     :
HelpLink       :
Source         :
HResult        : -2147024894

Message        : Could not load file or assembly 'Microsoft.Data.Services.Client, Version=5.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
FileName       : Microsoft.Data.Services.Client, Version=5.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
FusionLog      : WRN: Assembly binding logging is turned OFF.
                 To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
                 Note: There is some performance penalty associated with assembly bind failure logging.
                 To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Data           : {}
InnerException :
TargetSite     :
StackTrace     :
HelpLink       :
Source         :
HResult        : -2147024894

Message        : Could not load file or assembly 'Microsoft.Data.Services.Client, Version=5.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
FileName       : Microsoft.Data.Services.Client, Version=5.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
FusionLog      : WRN: Assembly binding logging is turned OFF.
                 To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
                 Note: There is some performance penalty associated with assembly bind failure logging.
                 To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Data           : {}
InnerException :
TargetSite     :
StackTrace     :
HelpLink       :
Source         :
HResult        : -2147024894

Message        : Could not load file or assembly 'Microsoft.Data.Services.Client, Version=5.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
FileName       : Microsoft.Data.Services.Client, Version=5.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
FusionLog      : WRN: Assembly binding logging is turned OFF.
                 To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
                 Note: There is some performance penalty associated with assembly bind failure logging.
                 To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Data           : {}
InnerException :
TargetSite     :
StackTrace     :
HelpLink       :
Source         :
HResult        : -2147024894

Attached Logs

Follow the instructions in the README about capturing and sending logs.

Environment Information

Visual Studio Code

Name Version
Operating System Windows_NT x64 10.0.19042
VSCode 1.48.1
PowerShell Extension Version 2020.7.0

PowerShell Information

Name Value
PSVersion 5.1.19041.1
PSEdition Desktop
PSCompatibleVersions 1.0 2.0 3.0 4.0 5.0 5.1.19041.1
BuildVersion 10.0.19041.1
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| |---|---|---| |better-toml|bungcip|0.3.2| |bracket-pair-colorizer-2|CoenraadS|0.2.0| |errorlens|usernamehw|3.2.0| |format-selection-as-html|adrianwilczynski|2.3.0| |github-linker|gimenete|0.2.3| |gitlens|eamodio|10.2.2| |line-endings|steditor|1.0.3| |markdown-all-in-one|yzhang|3.2.0| |material-icon-theme|PKief|4.2.0| |open-in-browser|techer|2.0.0| |powershell-preview|ms-vscode|2020.7.0| |project-manager|alefragnani|11.2.0| |run-in-powershell|tobysmith568|1.1.0| |vscode-markdownlint|DavidAnson|0.36.3| |vscode-pull-request-github|GitHub|0.19.0| |vscode-toggle-quotes|BriteSnow|0.3.3| |vscode-wakatime|WakaTime|4.0.0| |vscode-yaml|redhat|0.10.0| |xml|DotJoshJohnson|2.5.1|
SeeminglyScience commented 4 years ago

Still a module problem, just a different module. Some module is getting auto loaded that doesn't play well at type load. Note that this will only occur in Windows PowerShell as PowerShell Core will swallow these exceptions and continue searching.

PrzemyslawKlys commented 4 years ago

Well, that's a bummer. I believe a lot of my problems may be coming from something else then extension itself, but my problem is:

I'm pretty sure that all my hangings, stops of IntelliSense may be coming from outside of extension, and a lot of other people may be thinking that Code sucks because of it, when it's not entirely it's a fault. I'm having huge numbers of show stoppers in my case and I can imagine other people do as well but don't do any sort of reporting.

SeeminglyScience commented 4 years ago

Well, that's a bummer. I believe a lot of my problems may be coming from something else then extension itself (...) I'm pretty sure that all my hangings, stops of IntelliSense may be coming from outside of extension, and a lot of other people may be thinking that Code sucks because of it, when it's not entirely it's a fault. I'm having huge numbers of show stoppers in my case and I can imagine other people do as well but don't do any sort of reporting.

I know right? I suspect the same but it's difficult to prove and at the end of the day no one really cares whose fault it is (rightfully).

There's a whole lot of things that crop up like this when you start doing more than the basics because of finicky engine API's. This extension sees it more than something like the ISE partially because it just does more things. Fortunately a lot of these finicky API's are getting fixed, just not back ported.

Basically a lot of these API's were under used (or not used at all) so a lot of bugs were missed. Once we started using them more, they get caught and fixed. That's great but it does mean older more final versions of PowerShell are gonna feel kinda bad because they're a bit rickety.

  • tracking it - how do I know which module is offending in this case

Yeah it's a pain. Check out the assembly name and look around for a file that matches in your installed modules. You also might be able to find it doing something like this:

[AppDomain]::CurrentDomain.
    GetAssemblies().
    Where{ $_.GetReferencedAssemblies().Name -contains 'Full.Assembly.Name.Here' }.
    ForEach{ $_.GetName() }

Unfortunately it's often referenced assemblies of referenced assemblies so it's difficult to track down.

  • can Powershell extension "fix" it for 5.1 or are we doomed

Not cleanly :/ The problem is that it's the engine throwing really early into tab completion. Here's what happens:

  1. An assembly is loaded which clears the type completion cache
  2. TabExpansion2 is called
  3. Completion sees that the cache is cleared and goes to repopulate it
  4. Completion hits one of these type load errors before actually populating the cache and throws returning nothing
  5. Repeat from step 2

I have a script somewhere that manually repopulates the cache with big ol' piles of reflection. I'll see if I can dig it up but it's not a good solution generally because it's super expensive to run and in a lot of cases isn't actually needed. I used it a lot when I still had to live mostly in Windows PowerShell. It's tricky though because I often had to run it several times due to more assemblies loading and clearing the cache during the process of repopulating the cache... it's really unfortunate that that exception went uncaught for so long.

rjmholt commented 4 years ago

I'll see if I can dig it up but it's not a good solution generally because it's super expensive to run and in a lot of cases isn't actually needed

It may be, once other work is done, we could do something like detect an exception like this in tab completion somehow and have our own cache invalidation logic within PSES.

I know we chalk a lot of issues in the extension up to PowerShell itself being a difficult platform, and having worked on it for a while, it absolutely is (and not in obvious ways). BUT, as an editor/IDE we have to own the challenge of being robust, which is generally a case of shaving the yak to catch all the nasty little exceptions and details and work out what on earth we do with them.

SeeminglyScience commented 4 years ago

It may be, once other work is done, we could do something like detect an exception like this in tab completion somehow and have our own cache invalidation logic within PSES.

Fair enough. And also looking at it again I'm remembering that it was really expensive because I wrote it in ~10 minutes as a stop gap. It can almost definitely be written in a noticeably more performant way:

https://github.com/SeeminglyScience/dotfiles/blob/c4fa75ceddbdb5d9b6d16b90428969cc1c37fbe7/PowerShell/SetTypeCache.ps1

NOTE: Actually invoking that requires this function from my profile and the PSLambda module installed.

I know we chalk a lot of issues in the extension up to PowerShell itself being a difficult platform, and having worked on it for a while, it absolutely is (and not in obvious ways). BUT, as an editor/IDE we have to own the challenge of being robust, which is generally a case of shaving the yak to catch all the nasty little exceptions and details and work out what on earth we do with them.

Yeah I agree. The user doesn't (and shouldn't have to) care where the problem really is, especially if it only surfaces with us. I tried to convey that above but I may have over explained the negative a little.

PrzemyslawKlys commented 4 years ago
[AppDomain]::CurrentDomain.GetAssemblies().Where{ $_.GetReferencedAssemblies().Name -contains 'Microsoft.Data.Services.Client' }.ForEach{ $_.GetName() } | Format-Table Name, Version, CodeBase
Microsoft.Open.AzureAD16.Graph.Client               2.0.0.0 file:///C:/Users/przemyslaw.klys/Documents/WindowsPowerShell/Modules/AzureADPreview/2.0.2.62/Microsoft.Open.AzureAD16.Graph.Client.dll
Microsoft.Open.AzureADBeta.Graph.Client             2.0.0.0 file:///C:/Users/przemyslaw.klys/Documents/WindowsPowerShell/Modules/AzureADPreview/2.0.2.62/Microsoft.Open.AzureADBeta.Graph.Client.dll
Microsoft.Open.MS.GraphBeta.Client                  2.0.0.0 file:///C:/Users/przemyslaw.klys/Documents/WindowsPowerShell/Modules/AzureADPreview/2.0.2.62/Microsoft.Open.MS.GraphBeta.Client.DLL
Microsoft.Online.Administration.Automation.PSModule 1.1.0.0 file:///C:/Program Files/WindowsPowerShell/Modules/MSOnline/1.1.183.57/Microsoft.Online.Administration.Automation.PSModule.dll
Microsoft.Azure.ActiveDirectory.GraphClient         2.1.1.0 file:///C:/Program Files/WindowsPowerShell/Modules/MSOnline/1.1.183.57/Microsoft.Azure.ActiveDirectory.GraphClient.dll

image

Thanks @SeeminglyScience - I tracked it to 2.0.2.62 old preview which I have installed (also newer ones). Deleted it and will see what happens. I guess I have to use some cleanup utility which will remove old modules that are available across computers.

I always assumed only newest is autoloader but seems it's not true. So need to be careful now :-)

rjmholt commented 4 years ago

I always assumed only newest is autoloader but seems it's not true

The first one on the module path is autoloaded. In your case, the module in your user module path precedes the ones in the shared path, so is loaded despite its lower version. Also note that when two versions of the same module occur under the same path (like 2.0.2.105 and 2.0.2.102 here), the newest wins.