Skip to content
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

PowerShell: can't load Microsoft.PowerShell.Utility. #377

Closed
Ba4bes opened this issue Dec 20, 2019 · 18 comments
Closed

PowerShell: can't load Microsoft.PowerShell.Utility. #377

Ba4bes opened this issue Dec 20, 2019 · 18 comments
Assignees

Comments

@Ba4bes
Copy link

Ba4bes commented Dec 20, 2019

I have the same error as mentioned in this issue.

[Process:4688]: PS C:> The module 'Microsoft.PowerShell.Utility' could not be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Utility'. At line:0 char:0

[Process:4688]: PS C:> Debug-Runspace : The term 'Debug-Runspace' 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.

It started somewhere when I installed the latest Core Tools.
I use version 2.7.1948 through Chocolatey
I have .net Core SDK version 2.1, 2.2 and 3.1

I have two different VSCode environments (regular and insiders), PowerShell preview and regular, PowerShell extension preview and regular, it really doesn't seem to matter what combination I pick.
(all of these are on the latest versions)

Also tried reinstalling .net Core SDKs and Azure Core Function tools. No luck so far.

@Francisco-Gamino Francisco-Gamino self-assigned this Dec 20, 2019
@Francisco-Gamino
Copy link
Contributor

Francisco-Gamino commented Dec 20, 2019

Hello @Ba4bes,

Are you getting this error when you run the function app using the Core Tools? Or when running the Core Tools via VSCode?

Could you please send me the the following outputs?

PS C:\> func --version
2.7.1948
PS C:\> dotnet --info                                                                                                                                                                                                                                                                     .NET Core SDK (reflecting any global.json):
 Version:   3.1.100
 Commit:    cd82f021f4

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18363
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.1.100\

Host (useful for support):
  Version: 3.1.0
  Commit:  65f04fb6db

.NET Core SDKs installed:
  1.0.0-preview2-003131 [C:\Program Files\dotnet\sdk]
  1.1.14 [C:\Program Files\dotnet\sdk]
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.508 [C:\Program Files\dotnet\sdk]
  2.1.509 [C:\Program Files\dotnet\sdk]
  2.1.801 [C:\Program Files\dotnet\sdk]
  2.2.109 [C:\Program Files\dotnet\sdk]
  2.2.401 [C:\Program Files\dotnet\sdk]
  3.1.100 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 1.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 1.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 1.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download
PS C:\>                                                                                                                                                

Thanks,
Francisco

@Ba4bes
Copy link
Author

Ba4bes commented Dec 21, 2019

Hi @Francisco-Gamino , thank you for your time!
I use the core tools from VSCode, with the Azure Functions extension.
So I create a local Azure Function and try to run the debug mode, that is where the failure happens.

C:\> func --version
2.7.1948

C:\> dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   3.1.100     
 Commit:    cd82f021f4  

Runtime Environment:    
 OS Name:     Windows   
 OS Version:  10.0.18362
 OS Platform: Windows   
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.1.100\

Host (useful for support):
  Version: 3.1.0
  Commit:  65f04fb6db

.NET Core SDKs installed:
  2.1.607 [C:\Program Files\dotnet\sdk]
  2.2.207 [C:\Program Files\dotnet\sdk]
  3.1.100 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

In an effort to get this to work I had removed all the .NET Core SDKs (and the Function Core tools) and start reinstalling them as needed, these 3 versions seemed to be the ones, but maybe I would need something else.
I have the Azure Function Core tools installed through chocolatey if it makes a difference.

@Francisco-Gamino
Copy link
Contributor

Thank you @Ba4bes for the additional information. Could you please try the following?

  1. Open pswsh (PowerShell) and run func --version. Do you get an output here? If you do, then move to step 2. If you don't, then let me know and we'll fix this first.

image

  1. Open VSCode --> Open your PowerShell function app --> Go to the Terminal window. Remove all shells from the drop down box. Then, add pwsh as the default shell. After this, go the Terminal window and run: func. You should see some output here. If you do, go to step 3.

Your VSCode should look like this:
image

  1. Add Wait-Debugger in your run.ps1 script and hit F5.

Thanks,
Francisco

@Francisco-Gamino
Copy link
Contributor

Hello @Ba4bes, I am going to be out of the office for a couple of weeks, and I will not be able to look at this until I come back on 1/7/20.

Thanks,
Francisco

@Ba4bes
Copy link
Author

Ba4bes commented Dec 24, 2019

hi @Francisco-Gamino ,
Thank you so much for your time and effort.

I did all the steps that you described, got all the output you described. But after step 3 the same thing happens. I have the feeling the function isn't even hit, so it doesn't hit Wait-Debugger.

What I do see, is that even if I put it in pwsh (which already is the default, it switches to the PowerShell integrated Console before func is called. I have now found that if I have a 3rd pwsh-window, it returns to that window when the function app crashes. So it doesn't give that error.

Another thing I noticed is that there is a warning about dotnet not being in c:\program files(x86)\dotnet, so that Path will be used.

When I run func host start in pwsh, it doesn't throw (although the function isn't working when it should).

So I'm not sure if this is a problem with dotnet or VSCode or...
To see what happens I have completely reinstalled VsCode insiders, cleared the settings and only installed the PowerShell and the Azure Function extension. I still get the same error.

@Ba4bes
Copy link
Author

Ba4bes commented Dec 29, 2019

Alright I have made process. This might have been because I played around with the dotnet installation, but I got it working in VSCode now when I use Func Host Start.
The issues start when I use the debug-button in vscode. So the problem is not with the Function Core tools, but with either the PowerShell extension or the Azure Functions extension.

@Francisco-Gamino thank you for your help. I guess this issue needs to be in another place. Do you have an idea if this could be the PowerShell extension or the Azure Functions Extension? (Or am I completely off?)

@Francisco-Gamino
Copy link
Contributor

Francisco-Gamino commented Jan 6, 2020

Hi @Ba4bes, apologies for the delay, but I was OOF on vacation.

Sounds like this is an issue related to pwsh not being default terminal in the VSCode Extension.
Could you please remove all other shells (from the default terminal) and add only add pwsh?

image

If this does not fix the issue, let's setup a call to debug this. What's you availability this week?

Thanks,
Francisco

@Ba4bes
Copy link
Author

Ba4bes commented Jan 8, 2020

I have pwsh as the default terminal and when I type "func host start" evertything works as expected.

When I use the debug button in vscode though, it opens up the PowerShell integrated console and that is when I get the error. This is why I suspect now that it is an issue with the PowerShell extension instead of the PowerShell Function Core tools.

This is what happens after I press the debug button, you can see the switch:
image
The breaking point is about the same time as the debug mode starts and the edges become red

@Francisco-Gamino
Copy link
Contributor

Francisco-Gamino commented Jan 8, 2020

Hi @Ba4bes,

What version of pwsh are you using? You can get this information by running $PSVersionTable in pwsh.

Are you available for a videocall? If you are, Here is my availability in Pacific Standard Time:
1/8/20: 9:30-11:30 am, 1-2:30 pm, 3-4 pm
1/9/20: 1-2 and 3-4 pm
1/10/20: 9-11:30 and 3-4 pm

Let me know what day and time works for you. Please share an email where I can send the meeting request.

Thanks,
Francisco

@Ba4bes
Copy link
Author

Ba4bes commented Jan 9, 2020

Powershell version:

Name                           Value
----                           -----
PSVersion                      6.2.3
PSEdition                      Core
GitCommitId                    6.2.3
OS                             Microsoft Windows 10.0.18362 
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}        
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0    

Powershell extension in vscode

Name: PowerShell
Id: ms-vscode.powershell
Description: Develop PowerShell scripts in Visual Studio Code!
Version: 2019.12.0
Publisher: Microsoft
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-vscode.PowerShell

Azure Functions Extension in vscode

Name: Azure Functions
Id: ms-azuretools.vscode-azurefunctions
Description: An Azure Functions extension for Visual Studio Code.
Version: 0.20.1
Publisher: Microsoft
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions

I'm in Central European Time, so there are not a lot of time zone overlaps. Would between 11AM and 1PM PST work for you today (Thursday)?

@Francisco-Gamino
Copy link
Contributor

Francisco-Gamino commented Jan 9, 2020

Hello @Ba4bes, I could do 11 am to 12 pm today. Let me know if you are available. Also, what's your email address?

If this does not work. Are you available tomorrow 1/10? If you are, this is my availability: 9am-12pm and 3-4 pm.

@Ba4bes
Copy link
Author

Ba4bes commented Jan 9, 2020

Hey @Francisco-Gamino ,
I'm sorry, something came up, I can't make it today. I can make 9AM work tomorrow
I have just followed you on Twitter, could you send me a private message? That way I don't have to put my email address on the internet :)

@Francisco-Gamino
Copy link
Contributor

Hi @Ba4bes -- 9 am works. Please send me your email address via private message.

@Ba4bes
Copy link
Author

Ba4bes commented Jan 9, 2020

Great! I can't send you a message though unless you follow me or you start the conversation 😉

@Francisco-Gamino
Copy link
Contributor

Hey @Ba4bes, I sent you a private message. Please reply. I will talk to you tomorrow at 9 am. Have a good night.

@Francisco-Gamino Francisco-Gamino transferred this issue from Azure/azure-functions-core-tools Jan 14, 2020
@Francisco-Gamino
Copy link
Contributor

Francisco-Gamino commented Jan 14, 2020

This issue is not caused by the Core Tools, so moving to the PowerShell Worker for tracking.

@Ba4bes
Copy link
Author

Ba4bes commented Jan 22, 2020

After extensive troubleshooting we have found no way to fix this issue, but also no way to reproduce.
I have reinstalled my laptop (while keeping files) and removed all my profile-folders that start with a dot.
This has fixed the issue. Thank you everyone for your time and effort. I will close this issue.

@Francisco-Gamino
Copy link
Contributor

You are welcome @Ba4bes. I am glad the debugging issue was issue was resolved. Please do not hesitate to reach out if you ever need help for PowerShell in Functions.

Thanks,
Francisco

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants