roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

Code fix add nuget package crashes Visual Studio

Open jmarolf opened this issue 9 years ago • 13 comments

Version Used: Visual Studio 2017 RC.2 15.0.26009.0

Steps to Reproduce:

Try and add ValueTuple nuget package via codefix in roslyn.

Expected Behavior:

ValueTuple nuget package is added.

Actual Behavior:

Visual Studio Crashes

Application: devenv.exe
Framework Version: v4.0.30319
Description: The application requested process termination through System.Environment.FailFast(string message).
Stack:
   at Microsoft.VisualStudio.Shell.Interop.IVsBuildPropertyStorage.GetItemAttribute(UInt32, System.String, System.String ByRef)
   at NuGet.PackageManagement.VisualStudio.VSProjectRestoreReferenceUtility.GetExcludedReferences(EnvDTE.Project, Microsoft.VisualStudio.Shell.Interop.IVsEnumHierarchyItemsFactory)
   at NuGet.PackageManagement.VisualStudio.VSProjectRestoreReferenceUtility+<>c__DisplayClass0_0+<<GetDirectProjectReferences>b__0>d.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.InvokeMoveNext(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run()
   at Microsoft.VisualStudio.Threading.JoinableTaskFactory+SingleExecuteProtector.TryExecute()
   at Microsoft.VisualStudio.Threading.JoinableTask.CompleteOnCurrentThread()
   at NuGet.VisualStudio.VsPackageInstaller.InstallLatestPackage(System.String, EnvDTE.Project, System.String, Boolean, Boolean)
   at System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Object[], System.Signature, Boolean)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(System.Object, System.Object[], System.Object[])
   at System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
   at Microsoft.VisualStudio.LanguageServices.Packaging.PackageInstallerService+PackageServicesProxy.InstallLatestPackage(System.String, EnvDTE.Project, System.String, Boolean, Boolean)
   at Microsoft.VisualStudio.LanguageServices.Packaging.PackageInstallerService.TryInstallPackage(System.String, System.String, System.String, Boolean, EnvDTE.DTE, EnvDTE.Project)
   at Microsoft.VisualStudio.LanguageServices.Packaging.PackageInstallerService.TryInstallAndAddUndoAction(System.String, System.String, System.String, Boolean, EnvDTE.DTE, EnvDTE.Project, Microsoft.VisualStudio.OLE.Interop.IOleUndoManager)
   at Microsoft.VisualStudio.LanguageServices.Packaging.PackageInstallerService.TryInstallPackage(Microsoft.CodeAnalysis.Workspace, Microsoft.CodeAnalysis.DocumentId, System.String, System.String, System.String, Boolean, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.AddPackage.InstallPackageDirectlyCodeActionOperation.TryApply(Microsoft.CodeAnalysis.Workspace, Microsoft.CodeAnalysis.Shared.Utilities.IProgressTracker, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.CodeFixes.AddImport.AbstractAddImportCodeFixProvider`1+PackageReference+InstallPackageAndAddImportOperation[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].TryApply(Microsoft.CodeAnalysis.Workspace, Microsoft.CodeAnalysis.Shared.Utilities.IProgressTracker, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.Editor.Implementation.CodeActions.CodeActionEditHandlerService.ProcessOperations(Microsoft.CodeAnalysis.Workspace, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.CodeActions.CodeActionOperation>, Microsoft.CodeAnalysis.Shared.Utilities.IProgressTracker, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.Editor.Implementation.CodeActions.CodeActionEditHandlerService+<ApplyAsync>d__7.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[[Microsoft.CodeAnalysis.Editor.Implementation.CodeActions.CodeActionEditHandlerService+<ApplyAsync>d__7, Microsoft.CodeAnalysis.EditorFeatures, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]](<ApplyAsync>d__7 ByRef)
   at Microsoft.CodeAnalysis.Editor.Implementation.CodeActions.CodeActionEditHandlerService.ApplyAsync(Microsoft.CodeAnalysis.Workspace, Microsoft.CodeAnalysis.Document, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.CodeActions.CodeActionOperation>, System.String, Microsoft.CodeAnalysis.Shared.Utilities.IProgressTracker, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction+<InvokeWorkerAsync>d__20.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.InvokeMoveNext(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run()
   at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation+<>c.<.cctor>b__8_0(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)

jmarolf avatar Dec 14 '16 05:12 jmarolf

@rrelyea mentioned that @emgarten and @alpaix were looking into some JTF issues.

joelverhagen avatar Jan 11 '17 00:01 joelverhagen

I'm not sure if it's a JTF issue. It seems to be some sort of issue here:

   at Microsoft.VisualStudio.Shell.Interop.IVsBuildPropertyStorage.GetItemAttribute(UInt32, System.String, System.String ByRef)
   at NuGet.PackageManagement.VisualStudio.VSProjectRestoreReferenceUtility.GetExcludedReferences(EnvDTE.Project, Microsoft.VisualStudio.Shell.Interop.IVsEnumHierarchyItemsFactory)

CyrusNajmabadi avatar Jan 11 '17 00:01 CyrusNajmabadi

@CyrusNajmabadi Can you elaborate on detailed steps to get a repro?

alpaix avatar Jan 11 '17 01:01 alpaix

@CyrusNajmabadi Why did the project system crash here?

This hasn't changed in NuGet since it was added around VS 2015 Update 2 or so. Any ideas why codefix causes this?

Here is the relevant code: https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Clients/PackageManagement.VisualStudio/Utility/VSProjectRestoreReferenceUtility.cs#L139-L201

emgarten avatar Jan 11 '17 01:01 emgarten

Also, this build is 1 month old. Can you try recent d15rel builds please?

rrelyea avatar Jan 11 '17 01:01 rrelyea

Unfortunately, the problem is in the call to: buildPropertyStorage.GetItemAttribute. But hte stack doesn't make it clear what implementation of that method is being called. My guess is that it's a bad 3rd party implementation of IVsBuildPropertyStorage. It's throwing for some reason, and we're not resilient to it.

CyrusNajmabadi avatar Jan 11 '17 02:01 CyrusNajmabadi

@jmarolf I don't repro this myself. Can you try and see if you still hit it ?

CyrusNajmabadi avatar Jan 11 '17 02:01 CyrusNajmabadi

Unfortunately, the problem is in the call to: buildPropertyStorage.GetItemAttribute

It seems like the only fix then would be to catch all exceptions and provide a default, which isn't uncommon for these calls but I'd like to avoid that if possible.

emgarten avatar Jan 11 '17 02:01 emgarten

Ok. let's see if this still reproes. If so, we may have to do the 'catch all' approach. If not, then we can maybe just close this.

CyrusNajmabadi avatar Jan 11 '17 02:01 CyrusNajmabadi

@jmarolf Do you still repro this?

CyrusNajmabadi avatar Jan 19 '17 16:01 CyrusNajmabadi

@CyrusNajmabadi checking now

jmarolf avatar Jan 19 '17 19:01 jmarolf

Moving to @jmarolf to get a repro for this.

Pilchie avatar Jan 20 '17 03:01 Pilchie

I can't repro this on the latest build

jmarolf avatar Feb 11 '17 12:02 jmarolf