msgraph-sdk-powershell icon indicating copy to clipboard operation
msgraph-sdk-powershell copied to clipboard

connect-graph does not load in Visual Code

Open iaragon76 opened this issue 6 years ago • 4 comments

Dears,

I did the installation using install-module Microsoft.Graph without error or issues on a server.

While trying to work on Visual Code, the command connect-graph results in error:

Connect-Graph : The term 'Connect-Graph' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1

  • Connect-Graph -CertificateName
  •   + CategoryInfo          : ObjectNotFound: (Connect-Graph:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
    
    

However, if I go to Powershell ISE on the same server, it runs without issues.

I tried of course to force the import-module Microsoft.Graph.Authentication module in VSCode, but it triggers an error that cannot be mounted twice.

Here is the powershell version: Name Value


PSVersion 5.1.14393.2969 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.14393.2969 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1

Both in VSCode and Powershell ISE.

I enabled the developer log level for the powershell extension in VSCode. Some pieces of it:


2020-06-01 21:47:02.348 +02:00 [VRB] Attempting to execute command(s):

Microsoft.PowerShell.Core\Get-Command Connect-Graph -ErrorAction Ignore

2020-06-01 21:47:02.348 +02:00 [VRB] Session state changed --

Old state: Ready
New state: Running
Result: NotFinished

2020-06-01 21:47:02.402 +02:00 [VRB] Assembly resolve event fired for Microsoft.Graph.Authentication 2020-06-01 21:47:02.410 +02:00 [VRB] Session state changed --

Old state: Running
New state: Ready
Result: Completed

2020-06-01 21:47:02.410 +02:00 [ERR] Execution of the following command(s) completed with errors:

Microsoft.PowerShell.Core\Get-Command Connect-Graph -ErrorAction Ignore

2020-06-01 21:47:02.417 +02:00 [FTL] Failed to handle notification textDocument/hover System.NullReferenceException: Object reference not set to an instance of an object.


** Something is telling me that in VSCode, conenct-graph cannot make an instance of an object.

I'm attaching the full log to this post.

I would appreciate any lead I could get to see where to look forward. Thank you!

Running on a server,

OS Name Microsoft Windows Server 2016 Datacenter Version 10.0.14393 Build 14393

AB#7408

iaragon76 avatar Jun 01 '20 20:06 iaragon76

This happens to me on the "PowerShell Integrated Console." If i change my terminal to the default powershell terminal, or another powershell terminal it works (using F8 to run).

jagrock avatar Jun 10 '20 18:06 jagrock

This has something to do with VSCode using a runspace to initiate the ISE console - here's the verbose output for importing the module with -force. I can typically get it to load once per computer reboot.

import-module Microsoft.Graph.Authentication -Force -Verbose

VERBOSE: Loading module from path 'C:\Program Files\PowerShell\Modules\Microsoft.Graph.Authentication\0.5.1\Microsoft.Graph.Authentication.psd1'.
VERBOSE: Loading 'FormatsToProcess' from path 'C:\Program Files\PowerShell\Modules\Microsoft.Graph.Authentication\0.5.1\Microsoft.Graph.Authentication.format.ps1xml'.
VERBOSE: Populating RepositorySourceLocation property for module Microsoft.Graph.Authentication.
VERBOSE: Loading module from path 'C:\Program Files\PowerShell\Modules\Microsoft.Graph.Authentication\0.5.1\Microsoft.Graph.Authentication.psm1'.
Import-Module: C:\Program Files\PowerShell\Modules\Microsoft.Graph.Authentication\0.5.1\Microsoft.Graph.Authentication.psm1:13:9
Line |
  13 |  $null = Import-Module -Name (Join-Path $PSScriptRoot '.\bin\Microsoft …
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | An instance of GraphSession already exists. Call Initialize(Func<GraphSession>, bool) to overwrite it.

BatmanAMA avatar Jun 23 '20 16:06 BatmanAMA

@iaragon76, Is the issue still present? I'm not able to reproduce this with the latest version of the SDK https://www.powershellgallery.com/packages/Microsoft.Graph/1.2.0.

I'm using:

  • VS Code 1.52.1
  • PowerShell Integrated Console v2020.6.0
  • PowerShell version 7.1.0
  • MS Graph PowerShell SDK v1.2.0

peombwa avatar Dec 18 '20 23:12 peombwa

Closing since the issue is no longer reproducible with the latest versions. Feel free to open a new issue if this issue persists.

peombwa avatar Jan 29 '21 00:01 peombwa