Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

VS2015 Nuget Console not loading #1638

Closed
pete1208 opened this Issue Oct 26, 2015 · 67 comments

Comments

Projects
None yet

If do not have any solution open, I can open the package manager console. If I then open a solution, VS2015 crashes.

If I restart visual studio with no package manager console open, then open a solution, then choose package manager console, I get the following error:

"The type initializer for 'System.Management.Automation.Runspaces.InitialSessionState' threw an exception."

When this happens I do not get command prompt.
Environment: Win10 32bit, VS2015

Any help would be appreciated.
-Pete

Contributor

emgarten commented Oct 26, 2015

Try updating to the latest 3.2.1-rc VSIX here: https://dist.nuget.org/index.html

Does this happen with any solution? Does creating a new project also show this error?

I've updated to Package Manager Console Host Version 3.2.1.10581 and the results are the same.

Now here's a something to consider, if I create a powershell project and open that, VS2015 will crash. I can see the project files for a moment, then it crashes.

I've tried re-installing powershell and have net 3.5 & 4.6 installed in windows features. I also disabled my anti-virus with no affect.

Can you share a solution that crashes for you?

Also - Do you have powershell tools installed (https://visualstudiogallery.msdn.microsoft.com/c9eb3ba8-0c59-4944-9a62-6eee37294597)?

What happens if you remove them?

Any other extension installed on your visual studio?

I've had the powershell tools installed, then removed them and tried, then re-installed and tried with the same result.

As far as a project goes, it is as simple as creating a default C# WPF or C# Forms project. Then going using the tools / nuget / console command with the project open. No special references for anything, just the default starter project.

I've repaired VS2015, reinstalled powershell, etc... I wonder if it's a Win10 32 bit issue. Or VMWare issue. The Win10 x86 instance is hosted as guest on VMWare Workstation 12 Pro.

Funny thing is, the console works when no project is open. So I'm guessing the error related to reading what the project info..?

I've played around with changing the execution policy, with no effect.

The only extensions installed from the default are SQL Prompt and Visual Studio Spell Checker.

Any ideas would be appreciated.

Ok, i've tried modifying devenv.exe.config. I can now get the console up when a project is open, but there are some errors. However the console prompt does appear.

Changes to config file:

<!-- pete added these entries start -->
<dependentAssembly>
        <assemblyIdentity name="System.Management.Automation" publicKeyToken="31bf3856ad364e35" />
        <publisherPolicy apply="no" />
      </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.PowerShell.Commands.Utility" publicKeyToken="31bf3856ad364e35" />
      <publisherPolicy apply="no" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.PowerShell.ConsoleHost" publicKeyToken="31bf3856ad364e35" />
      <publisherPolicy apply="no" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.PowerShell.Commands.Management" publicKeyToken="31bf3856ad364e35" />
      <publisherPolicy apply="no" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.PowerShell.Security" publicKeyToken="31bf3856ad364e35" />
      <publisherPolicy apply="no" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.PowerShell.Commands.Diagnostics" publicKeyToken="31bf3856ad364e35" />
      <publisherPolicy apply="no" />
    </dependentAssembly>

<!-- pete added end -->

Now when the prompt appears and a project is open, i get a few errors:

The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\WINDOWS\System32\WindowsPowerShell\v1.0\types.ps1xml(386) : Error in type "System.IO.DirectoryInfo": Exception: Cannot convert the "Microsoft.PowerShell.Commands.InternalSymbolicLinkLinkCodeMethods" value of type "System.String" to type "System.Type".
The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\WINDOWS\System32\WindowsPowerShell\v1.0\types.ps1xml(393) : Error in type "System.IO.DirectoryInfo": Exception: Cannot convert the "Microsoft.PowerShell.Commands.InternalSymbolicLinkLinkCodeMethods" value of type "System.String" to type "System.Type".
The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\WINDOWS\System32\WindowsPowerShell\v1.0\types.ps1xml(433) : Error in type "System.IO.FileInfo": Exception: Cannot convert the "Microsoft.PowerShell.Commands.InternalSymbolicLinkLinkCodeMethods" value of type "System.String" to type "System.Type".
The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\WINDOWS\System32\WindowsPowerShell\v1.0\types.ps1xml(440) : Error in type "System.IO.FileInfo": Exception: Cannot convert the "Microsoft.PowerShell.Commands.InternalSymbolicLinkLinkCodeMethods" value of type "System.String" to type "System.Type".
Each package is licensed to you by its owner. Microsoft is not responsible for, nor does it grant any licenses to, third-party packages. Some packages may include dependencies which are governed by additional licenses. Follow the package source (feed) URL to determine any dependencies.

Package Manager Console Host Version 3.2.1.10581

Type 'get-help NuGet' to see all available NuGet commands.

PM>

********* so I'm making progress

I've just tried it, and the above workaround allows the entity framework to install, so I'm happy.

@pete1208 pete1208 closed this Oct 29, 2015

mhutch commented Nov 25, 2015

FWIW, I ran into this on Win10 x64. Googling the error message indicated that when it came up in another context, it could fixed by repairing .NET 3.5, so I went to Windows Optional Features and removed .NET 3.5 entirely. That fixed it in this case too. No idea why though!

I tried that uninstalling 3.5, with no luck. I am using using a VM Workstation guest OS Win10 x86. By adding the config lines above it works, if I remove them it fails. There are no error messages when opening the console now too

@pete1208 any chance we can get access to a machine with this failure?

mrlund commented Nov 28, 2015

If it helps, I just had the same issue, running 2015 Update 1 RC on Win10 x64, with an MVC project opened in a new instance after another instance open with a Cordova project. I closed both of them down, and reopened just the MVC project, and the console was working again.

The problem is that we cannot get a local repro. Is it possible to get access to a machine this happens on?

I was just able to fix this by removing the Nuget extension (via extensions and updates), rebooting, reinstalling it, then rebooting.

@fuxuepeng we have seen some issues with the MEF catalog in Visual Studio not refreshing properly, and a reinstall or a call to devenv /setup resolves it.

now that Update I is out, I recommend to whoever is experiencing this to try again with a fresh install.

JeremyBP commented Dec 2, 2015

@yishaigalatzer Still the same error: "The type initializer for 'System.Management.Automation.Runspaces.InitialSessionState' threw an exception" when opening the console after a project loaded.

No exception on an empty VS session, the console opened just fine, but if I then open a project, VS goes stucked and I have to restart it.

All above solutions tried with no luck.

Env: Win 10 x64 up to date, VS 2015 CE with U1 & Nuget 3.3.0.167 & Azure SDK 2.8.1

pete1208 commented Dec 2, 2015

@yishaigalatzer - I could let you have access to this machine via join.me

@JeremyBP one thing that would be interesting to see is if you have any init.ps1 scripts in your installed nuget packages that are misbehaving. As an experiment can you scan your packages folder for such files and temporarily delete them? (You can always recover by wiping out the packages folder and restoring again).

@pete1208 I'm sick today, but I asked @feiling to work with you. Please email me @ y i g a l a t z @ microsoft.com and I'll forward the contact to him

feiling commented Dec 2, 2015

@pete1208 please send email to me (feiling at microsoft.com) so that we can figure out how/when I can get access to your machine.

JeremyBP commented Dec 7, 2015

@yishaigalatzer any progress about it?

I guess not for the last few days, since we where all on vacation on Friday. We will sync again today

JeremyBP commented Dec 7, 2015

ok
For info this message appears for me when trying to install Json.Net or SQLitePCL on a Xamarin.Android project, more exactly when executing the bundled install.ps1 script.
Workaround was to add each manually, but it's a workaround.
Also, changing PowerShell policies did not change anything.

feiling commented Dec 7, 2015

@pete1208

The most probable cause seems to that the powershell dlls (System.Management.Automation) that get loaded do not work with nuget.

Since we couldn't repro the problem, I created a simple extension that will list all loaded assemblies in VS:

GetLoadedAssemblies.zip

Download the file, change the extension to vsix and install it. Then in VS, you can run the new command Tools -> Get Loaded Assemblies to save the list of loaded assemblies into a file.

Please run the commands in these scenarios:

  • Open VS, open nuget powershell console, run the command
  • Open VS, open the solution that repros the problem, run the command

You can then upload the output files and we can take a look.

You can also compare the version/location of the powershell assemblies (e.g. System.Management.Automation) yourself and probably you can figure out why the wrong versions get loaded.

On my machine, the assembly is System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, location C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0__31bf3856ad364e35\System.Management.Automation.dll.

pete1208 commented Dec 8, 2015

When I edit the config it (and things work) get the assembly:

System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, location C:\WINDOWS\assembly\GAC_MSIL\System.Management.Automation\1.0.0.0__31bf3856ad364e35\System.Management.Automation.dll

When I don't edit the config:

System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, location C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0__31bf3856ad364e35\System.Management.Automation.dll

These are the loaded assemblies with each config per your tool.
Not working default config.txt
Working when I modified config.txt

feiling commented Dec 8, 2015

Could you zip the file C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0__31bf3856ad364e35\System.Management.Automation.dll and upload it here? If you can't, then pls right click on the dll to get its file version. For reference, the versions on some of my machines are 10.0.10565.0, 10.0.10240.16384.

Also, pls upload the solution/project that repros the problem.

Also, pls copy the info that you get from VS, Help -> About, then click the "Copy Info" button.

feiling commented Dec 8, 2015

@pete1208 Question about the file 'not working default config.txt': Did you create the file after you opened PowerShell console or after you opened the solution?

pete1208 commented Dec 8, 2015

Version Info: about.txt
'Not working default config' -- I opened the powershell window before any project was open. If a project is open, the system crashes.

The other additional requested uploads are here:
System_mgt_auto.zip
TestAppA.zip

@pete1208 one thing we forgot to ask is, can you please remove the spell checker and sql prompt and see if the problem goes away?

Can you poing to the links of these specific extensions in the extension gallery?

feiling commented Dec 8, 2015

@pete1208 I remember that the project can be opened successfully. The VS only crashes when you try to open PowerShell Console after that. Right? What we need is the list of loaded assemblies after the project is opened, but before you try to open PowerShell Console.

pete1208 commented Dec 9, 2015

With VS default config, no spell check or sql prompt.
Spell Check: https://visualstudiogallery.msdn.microsoft.com/a23de100-31a1-405c-b4b7-d6be40c3dfff?SRC=VSIDE
Sql Prompt: http://www.red-gate.com/products/sql-development/sql-prompt/

Here is what is loaded with default and project is open (giving the The type initializer for 'System.Management.Automation.Runspaces.InitialSessionState' threw an exception error)

default config no SQL spellchk proj opn.txt

oh, and VS will crash if the powershell window is opened before you open the project. If it is closed, and you open the project, then open the powershell window, I get the initializer error above. When I add the entries back to the config, all errors go away.

If you want, I can copy this virtual machine onto a usb HDD and send to you to debug. Requires VMWare workstation 12.

zman13 commented Dec 10, 2015

Having a similar problem. Since the RC update if I have the Package Manager Console tab open when I load VS 2013 (or 2015) it seems to initialize fine, but Visual Studio will crash whenever I try to publish our project which has not changed lately. However, if I don't have the Package Manager Console up initially and publish before opening the PMC tab it will publish the project properly but when I try to open the Package Manager Console tab I will get The type initializer for 'System.Management.Automation.Runspaces.InitialSessionState' threw an exception on the top line of the console. Very annoying behavior that was introduced with the update

@zman13 we are not aware on impacts on 2013 or an update that introduced it. Can you provide more details?

What do you mean by publishing? Can you share specifically what is going on?

zman13 commented Dec 10, 2015

sure, I meant publishing the project. (right clicking on the project and using the publish function in VS). When I choose this option (and I have opened VS with the PMC tab opened) the publish dialog will not come up instead visual studio will crash with a dialog that says:
Microsoft Visual Studio 2013 has stopped working A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available.
If PMC tab is not open then I can publish the project but when I open the PMC tab I get The type initializer for 'System.Management.Automation.Runspaces.InitialSessionState' threw an exception on the top line of the console

feiling commented Dec 10, 2015

@pete1208 We just couldn't figure out what might be the cause. We'll need access to your machine to debug the problem. Please make a copy of the VM and send it to us at

Microsoft Corporation
yigalatz 44/3S
1 Microsoft Way
Redmond, WA 98052

Will send with info needed to log in, etc...

@yishaigalatzer yishaigalatzer added this to the 3.4 milestone Dec 10, 2015

lju commented Dec 11, 2015

So I was having the exact same problem - same error with the same attempts to fix it. I worked around it by closing all instances of VS and then opening the Package Manager Console and then my project within a new instance of VS. The Console now stays up and no longer gives me that error. It's been fine ever since.

Disk with VM is on it's way. When you get it, if you open notepad++ it will have the devenv.conf file we've talked about.

I tried Lju's solution, with no luck.

Erucy commented Dec 12, 2015

same error as @zman13 . I've reinstalled all the environment I have, reset win10, reinstall vs2015 ent with update 1. Open my web project, click publish, close the dialog, open the package manager console, and then, bang! If I open the package manager console first, well, everything seems fine, until I open the publish dialog, the vs crash... All the softwares I have on my machine are windows 10 x64 ent th2, vs 2015 and office 2016.

Thank you everyone, the status is that we cannot get a repro in Redmond. @pete1208 has been kind enough to send us a vm, so when it gets to us we will take another look. Our assumption is that "something" is loading the wrong version of powershell into the visual studio host, and since the policy in visual studio is to only load one and that version is not compatible with what nuget is trying to do we fail loading the console. This is an inherent limitation of running inside a host on the same appdomain (which is required by the powershell console to talk directly to the visual studio objects)

At this point without a good root cause, or a good repro we are still trying to figure out what is going on. Hopefully when we get the vhd, we will be able to dig deeper. With the holiday season, I unfortunately suspect this might get dragged into early January before we can nail it down.

I can confirm that for my environment, everything's working great with nuget/powershell with any kind of project, except with Xamarin.Android project.
For ex, for cross-platform app:
. I create a new solution with a new pcl Core project => nuget console ok & json.net (with install script) install ok
. I add a new Xamarin.iOS project => nuget console ok & json.net install ok
. I add Uwp, WinPhone 8 & WinRT (win & phone) projects to solution => nuget console ok & json.net install ok
. Then I add a Xamarin.Android project => VS crash (VS crash only if nuget console was initialized yet)
. I reopen the solution => nuget console ko (powershell init failed) & json.net install ko (script failed)
. From here, json.net install/update on other projects fails to.

Don't know if @pete1208 was working with Xamarin to or if it's only about my personal environment.

Env: Win 10 x64 up to date, VS 2015 CE with U1 & Nuget 3.3.0.167 & Azure SDK 2.8.1

I'm still seeing this error with Xamarin.Android also... I had just tried Installing the XLab.Forms stuff from Nuget and it seems to have broken the Package Manager Console
Edit: Restarting the machine seems to have fixed it...

I reset the devenv.config back to the default and installed VS2015 Patch 1. The package manager console now works fine.

igrali commented Dec 21, 2015

Same repro steps as @zman13 and @Erucy described are causing a crash/Package Manager Console error on my side. Reinstalled VS 2015 Update 1, same thing is happening again. It's very annoying, so please keep us posted!

@igrali did the workaround that @pete1208 used (changing the config file) unblock you?

Erucy commented Dec 22, 2015

I just did the workaround as @pete1208 did. It seems make everything fine.

igrali commented Dec 22, 2015

Do you mean: do Devenv /ResetSettings and reinstall VS again or? I tried doing Devenv /ResetSettings but that didn't help :(

Change the config file is the suggestion.

igrali commented Dec 22, 2015

Oh, I see. Yeah, it seems that adding those entries to devenv.exe.config solved the problem for me - I was finally able to use Package Manager Console and publish my web app without a crash. Thanks! 😃

@pete1208 Thanks for sending us the disk with VM. We will take a look at it.

@pete1208 I tried to repro the issue you mentioned on the machine you provided and I can open the publish dialog with Package manager open without any issues. I also tried publishing the project and it works fine. Is there any repro steps that I am missing here?
publishdialog

Vijay can you run install-package command ?

Did you open notepad++ and remove the lines I added to the config? The current config is a work-around one

I can repro the PMC issue after removing the additional entries from devenv.exe.config. Web publish does work even when this error is thrown. Looking into it.

pmc_issue

I had this same error. Very annoying, seemed to appear out of nowhere, then I remembered my machine did one of those lovely "Updates". You know the Poltergeist moment after you go away and come back your screen says, "Hi". Very creepy, Microsoft. Tsk tsk. Well, after poking around some I found this article, which if you follow the steps might solve your problem as well.

Essentially, the "update" had jacked with the security settings in some way. I'd really prefer Microsoft not do these "updates" this way. Nonetheless after setting the ExecutionPolicy and restarting VS, all is well.

Hope this helps.

http://stackoverflow.com/questions/10457039/why-does-executionpolicy-behavior-vary-across-projects-in-visual-studio

@Pray4Wind thanks, but this looks like an unrelated issue to the one reported it (though very possible, something we do not control).

What we are seeing is that there is a stack overflow in the powershell code proper, we have reached out to the power shell team, and we are working on a potential temporary workaround in nuget itself.

UPDATE: We figured out this is a bug in System.Management.Automation 3.0 (on the specific image @pete1208 sent us), which is why the solution by @pete1208 (which basically downgrades to System.Management.Automation 1.0) makes it work again.

The fix is supposed to be released at some point in January as part of the windows update releases, when that happens we will update this issue with exact details on how to acquire it.

Same here, if package manager console is OK, publish will crash VS without any notice :(

cpolitz commented Jan 8, 2016

I am experiencing the exact same issue. If I close visual studio and open it fresh and open PackageManager console first it is fine. But then if I try to publish it crashes. If I open it fresh and publish first, that works fine however now PackageManager Console will error as described.

Same problem as @cpolitz here. VS2015, Windows 10, started sometime in the last two weeks without any apparent action from my side.

@Bilegbayar @cpolitz @joeyfr - See above comment, this seems to come from a PowerShell dll that has a bug causing stackoverflow in it. The scenario happens when some new assemblies are being loaded into the main appdomain after this powershell dll is loaded.

There is not much NuGet can do about it, until the Power Shell team releases their fix as part of windows update. I don't have an official date, but I believe it should happen this month.

@yishaigalatzer Thanks mate I didn't get it. Hopefully they will release it soon.

can you please post detailed instructions on the workaround? what caused this problem, was it windows update?

@piersh @pete1208 posts a workaround above where we uses binding redirects to force loading powershell 1.0, it is not something we guarantee to work all over, but it seems to be a good bandaid for some people.

Ok, i've tried modifying devenv.exe.config. I can now get the console up when a project is open, but there are some errors. However the console prompt does appear.

Changes to config file:

The problem with it is that it loads an older version of powershell for all of visual studio, and we have no idea what side effects it might have. Feel free to try at your own risk.

jontyt commented Jan 13, 2016

For anybody wanting an easy get around the nuget console issue -

"The type initializer for 'System.Management.Automation.Runspaces.InitialSessionState' threw an exception."

Simply reinstalling nuget from Visual studio fixed this issue for me.

@pete1208 the fix was released as part of https://support.microsoft.com/en-us/kb/3124263, could you install it and verify the problem is fixed for you?

Yes I am working without errors

Same here, this has been fixed

Thanks for validating the fix. This bug was a mystery for a while. Huge thanks to @pete1208 for the help mailing/nailing down a repro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment