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

ArgumentNullException thrown from NuGet.PackageManagement.VisualStudio.VSSettings.ResetSolutionSettings() #1408

Closed
AArnott opened this issue Sep 19, 2015 · 6 comments
Assignees
Labels
Priority:1 High priority issues that must be resolved in the current sprint. Type:Bug
Milestone

Comments

@AArnott
Copy link
Contributor

AArnott commented Sep 19, 2015

NuGet VS extension version: 3.2.60914.10516

  1. In Visual Studio 2015, File -> Open -> Open File
  2. Open a project.json file that belongs to a project (in my example, a desktop-targeted class library project)
  3. Put the caret on the version string of a Nuget package dependency expressed in that project.json file.
  4. Press Ctrl+J (to activate the intellisense completion dropdown)

The ArgumentNullException is thrown from Path.Combine when it is called from here.

    ---------------------------
    Microsoft Visual Studio
    ---------------------------
    An exception has been encountered. This may be caused by an extension.
    You can get more information by examining the file 'C:\Users\andarno\AppData\Roaming\Microsoft\VisualStudio\14.0exp\ActivityLog.xml'.
    ---------------------------
    OK   
    ---------------------------

The activity log contained this exception:

Microsoft.VisualStudio.Composition.CompositionFailedException: An exception was thrown while initializing part "NuGet.PackageManagement.VisualStudio.VSSettings". ---> System.ArgumentNullException: Value cannot be null. Parameter name: path1 at System.IO.Path.Combine(String path1, String path2) at NuGet.PackageManagement.VisualStudio.VSSettings.ResetSolutionSettings() at NuGet.PackageManagement.VisualStudio.VSSettings..ctor(ISolutionManager solutionManager, IMachineWideSettings machineWideSettings) --- End of inner exception stack trace --- at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.RuntimePartLifecycleTracker.CreateValue() at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.Create() at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveNext(PartLifecycleState nextState) at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveToState(PartLifecycleState requiredState) at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.GetValueReadyToExpose() at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.<>c__DisplayClass15_0.b__0() at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.GetValueForImportElement(RuntimePartLifecycleTracker importingPartTracker, RuntimeImport import, RuntimeExport export, Func3 lazyFactory) at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.GetValueForImportSite(RuntimePartLifecycleTracker importingPartTracker, RuntimeImport import) at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.RuntimePartLifecycleTracker.<CreateValue>b__10_0(RuntimeImport import) at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() at System.Linq.Buffer1..ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source) at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.RuntimePartLifecycleTracker.CreateValue() at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.Create() at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveNext(PartLifecycleState nextState) at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveToState(PartLifecycleState requiredState) at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.GetValueReadyToExpose() at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.<>c__DisplayClass15_0.<GetExportedValueHelper>b__0() at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.GetValueForImportElement(RuntimePartLifecycleTracker importingPartTracker, RuntimeImport import, RuntimeExport export, Func3 lazyFactory) at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.GetValueForImportSite(RuntimePartLifecycleTracker importingPartTracker, RuntimeImport import) at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.RuntimePartLifecycleTracker.b__10_0(RuntimeImport import) at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() at System.Linq.Buffer1..ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source) at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.RuntimePartLifecycleTracker.CreateValue() at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.Create() at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveNext(PartLifecycleState nextState) at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveToState(PartLifecycleState requiredState) at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.GetValueReadyToExpose() at Microsoft.VisualStudio.Composition.ExportProvider.<>c__DisplayClass53_0.b__0() at System.Lazy1.CreateValue() at System.Lazy1.LazyInitValue() at System.Lazy1.get_Value() at Microsoft.VisualStudio.Composition.NetFxAdapters.MefV1ExportProvider.<>c__DisplayClass12_0.<UnwrapExport>b__1() at System.ComponentModel.Composition.Primitives.Export.GetExportedValueCore() at System.ComponentModel.Composition.Primitives.Export.get_Value() at System.ComponentModel.Composition.ReflectionModel.ImportingItem.Cast(Type type, Export export) at System.ComponentModel.Composition.ReflectionModel.ImportingItem.CastSingleExportToImportType(Type type, Export export) at System.ComponentModel.Composition.ReflectionModel.ImportingItem.CastExportsToSingleImportType(Export[] exports) at System.ComponentModel.Composition.ReflectionModel.ImportingItem.CastExportsToImportType(Export[] exports) at System.ComponentModel.Composition.ReflectionModel.ReflectionComposablePart.SetImport(ImportingItem item, Export[] exports) at System.ComponentModel.Composition.ReflectionModel.ReflectionComposablePart.SetImport(ImportDefinition definition, IEnumerable1 exports) at System.ComponentModel.Composition.Hosting.ImportEngine.PartManager.TrySetImport(ImportDefinition import, Export[] exports) at System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImportSubset(PartManager partManager, IEnumerable1 imports, AtomicComposition atomicComposition) at System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImportsStateMachine(PartManager partManager, ComposablePart part) at System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImports(PartManager partManager, ComposablePart part, Boolean shouldTrackImports) at System.ComponentModel.Composition.Hosting.ImportEngine.SatisfyImports(ComposablePart part) at System.ComponentModel.Composition.Hosting.CompositionServices.GetExportedValueFromComposedPart(ImportEngine engine, ComposablePart part, ExportDefinition definition) at System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportedValue(CatalogPart part, ExportDefinition export, Boolean isSharedPart) at System.ComponentModel.Composition.Hosting.CatalogExportProvider.CatalogExport.GetExportedValueCore() at System.ComponentModel.Composition.Primitives.Export.get_Value() at System.ComponentModel.Composition.ExportServices.GetCastedExportedValue[T](Export export) at System.ComponentModel.Composition.ExportServices.<>c__DisplayClass02.b__1() at System.Lazy1.CreateValue() at System.Lazy1.LazyInitValue() at System.Lazy1.get_Value() at Clide.Commands.CommandManager.AddCommands() at Clide.HostImpl.Initialize() at Clide.Host.Initialize(IServiceProvider hostingPackage) at Xamarin.VisualStudio.Shell.IntegrationPackage.Initialize() at Microsoft.VisualStudio.Shell.Package.Microsoft.VisualStudio.Shell.Interop.IVsPackage.SetSite(IServiceProvider sp) --- End of stack trace from previous location where exception was thrown --- at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveToState(PartLifecycleState requiredState) at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.GetValueReadyToExpose() at Microsoft.VisualStudio.Composition.ExportProvider.<>c__DisplayClass53_0.<CreateExport>b__0() at System.Lazy1.CreateValue() at System.Lazy1.LazyInitValue() at System.Lazy1.get_Value() at Microsoft.VisualStudio.Composition.ExportProvider.<>c__DisplayClass70_02.<GetExports>b__1() at System.Lazy1.CreateValue() at System.Lazy1.LazyInitValue() at System.Lazy1.get_Value() at Microsoft.VisualStudio.Composition.ExportProvider.GetExportedValueT at Microsoft.VisualStudio.ComponentModelHost.ComponentModel.GetServiceT at NuGet.PackageManagement.VisualStudio.ServiceLocator.d__101.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NuGet.PackageManagement.VisualStudio.ServiceLocator.<>c__61.<b__6_0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.VisualStudio.Threading.JoinableTask.CompleteOnCurrentThread() at Microsoft.VisualStudio.Threading.JoinableTask1.CompleteOnCurrentThread() at Microsoft.VisualStudio.Threading.JoinableTaskFactory.Run[T](Func1 asyncMethod, JoinableTaskCreationOptions creationOptions) at Microsoft.VisualStudio.Threading.JoinableTaskFactory.Run[T](Func1 asyncMethod) at NuGet.PackageManagement.VisualStudio.ServiceLocator.GetInstance[TService]() at NuGet.PackageManagement.VisualStudio.VSSolutionManager.GetProjectFactory() at NuGet.PackageManagement.VisualStudio.VSSolutionManager.EnsureNuGetAndEnvDTEProjectCache() at NuGet.PackageManagement.VisualStudio.VSSolutionManager.OnSolutionExistsAndFullyLoaded() at NuGet.PackageManagement.VisualStudio.VSSolutionManager.OnCmdUIContextChanged(UInt32 dwCmdUICookie, Int32 fActive) --- End of stack trace from previous location where exception was thrown --- at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveToState(PartLifecycleState requiredState) at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.GetValueReadyToExpose() at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.<>c__DisplayClass15_0.<GetExportedValueHelper>b__0() at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.GetValueForImportElement(RuntimePartLifecycleTracker importingPartTracker, RuntimeImport import, RuntimeExport export, Func3 lazyFactory) at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.GetValueForImportSite(RuntimePartLifecycleTracker importingPartTracker, RuntimeImport import) at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.RuntimePartLifecycleTracker.b__10_0(RuntimeImport import) at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() at System.Linq.Buffer1..ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source) at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.RuntimePartLifecycleTracker.CreateValue() at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.Create() at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveNext(PartLifecycleState nextState) at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveToState(PartLifecycleState requiredState) at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.GetValueReadyToExpose() at Microsoft.VisualStudio.Composition.ExportProvider.<>c__DisplayClass53_0.b__0() at System.Lazy1.CreateValue() at System.Lazy1.LazyInitValue() at System.Lazy1.get_Value() at Microsoft.VisualStudio.Composition.NetFxAdapters.MefV1ExportProvider.<>c__DisplayClass12_0.<UnwrapExport>b__1() at System.ComponentModel.Composition.Primitives.Export.GetExportedValueCore() at System.ComponentModel.Composition.Primitives.Export.get_Value() at System.ComponentModel.Composition.ReflectionModel.ImportingItem.Cast(Type type, Export export) at System.ComponentModel.Composition.ReflectionModel.ImportingItem.CastSingleExportToImportType(Type type, Export export) at System.ComponentModel.Composition.ReflectionModel.ImportingItem.CastExportsToSingleImportType(Export[] exports) at System.ComponentModel.Composition.ReflectionModel.ImportingItem.CastExportsToImportType(Export[] exports) at System.ComponentModel.Composition.ReflectionModel.ReflectionComposablePart.SetImport(ImportingItem item, Export[] exports) at System.ComponentModel.Composition.ReflectionModel.ReflectionComposablePart.SetImport(ImportDefinition definition, IEnumerable1 exports) at System.ComponentModel.Composition.Hosting.ImportEngine.PartManager.TrySetImport(ImportDefinition import, Export[] exports) at System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImportSubset(PartManager partManager, IEnumerable1 imports, AtomicComposition atomicComposition) at System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImportsStateMachine(PartManager partManager, ComposablePart part) at System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImports(PartManager partManager, ComposablePart part, Boolean shouldTrackImports) at System.ComponentModel.Composition.Hosting.ImportEngine.SatisfyImportsOnce(ComposablePart part) at System.ComponentModel.Composition.Hosting.CompositionContainer.SatisfyImportsOnce(ComposablePart part) at Microsoft.VisualStudio.Composition.NetFxAdapters.CompositionService.SatisfyImportsOnce(ComposablePart part) at System.ComponentModel.Composition.AttributedModelServices.SatisfyImportsOnce(ICompositionService compositionService, Object attributedPart) at Microsoft.Web.Editor.ComponentLocator1.Import() at Microsoft.VisualStudio.JSON.Package.Completion.CompletionProviders.ProjectJSON.ProjectJSONHelpers.d__20.MoveNext() at Microsoft.VisualStudio.JSON.Package.Completion.CompletionProviders.ProjectJSON.ProjectJSONHelpers.GetRemotePackageSources() at Microsoft.VisualStudio.JSON.Package.Completion.CompletionProviders.ProjectJSON.ProjectJSONHelpers.GetPackageVersionsSearchResults(IEnumerable`1 frameworks, String packageId) at Microsoft.VisualStudio.JSON.Package.Completion.CompletionProviders.ProjectJSON.DependenciesValueCompletionProvider.GetListEntries(JSONCompletionContext context) at Microsoft.JSON.Editor.Completion.JSONCompletionSource.<>c__DisplayClass3_1.b__0() at Microsoft.Web.Editor.Utility.GuardedOperations.InvokeExtensionPoint(Object errorSource, Action action)

@yishaigalatzer yishaigalatzer added this to the 3.3.0-Beta milestone Sep 21, 2015
@yishaigalatzer yishaigalatzer added Priority:3 Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog. Type:Bug labels Sep 21, 2015
@yishaigalatzer
Copy link

I'm guessing it is coming from here:

 private void ResetSolutionSettings()
        {
            string root;
            if (SolutionManager == null
                || !SolutionManager.IsSolutionOpen)
            {
                root = null;
            }
            else
            {
                root = Path.Combine(SolutionManager.SolutionDirectory, EnvDTEProjectUtility.NuGetSolutionSettingsFolder);
            }
            SolutionSettings = Configuration.Settings.LoadDefaultSettings(root, configFileName: null, machineWideSettings: MachineWideSettings);
        }

In what scenario can the solution be closed and the folder be null? The code obviously allows for that, see here:

https://github.com/NuGet/NuGet.VisualStudioExtension/blob/dev/src/PackageManagement.VisualStudio/IDE/VSSolutionManager.cs#L250

So it seems the settings check should simply check for null instead of looking at IsSolutionOpen

@AArnott
Copy link
Contributor Author

AArnott commented Sep 22, 2015

The exception is ArgumentNullException and it's thrown from Path.Combine.
The circumstance is that the user opens a project.json file but doesn't open the project or solution that contains it. VS can't open a file by itself. There is always a solution and a "Miscellaneous Files" project to host a stray opened file. This anonymous solution has not been saved, and therefore has no solution directory of its own. That's probably why your SolutionManager.SolutionDirectory property is returning null.

@deepakaravindr
Copy link

@AArnott , That makes sense. We will fix it.

Little bit of history on this issue below

In VS 2013, NuGet would treat the File->NewFile solution and an unsaved solution (when the project file is directly opened or if a newly created project is not saved by default) as the same. Meaning, NuGet will be unsupported in those scenarios. Because, NuGet needs the solution directory to install packages and does not want to use the SolutionDirectory from an unsaved solution or if it is not available. In fact, SolutionManager will 'false' for SolutionManager.IsSolutionOpen and null for SolutionManager.SolutionDirectory, even though, the solution is actually open and not null for unsaved solutions.

We have changed this in NuGet3, where in, NuGet may be supported even if a solution is unsaved, so long as the packages folder does not depend on the SolutionDirectory. For example, UWP applications with a default globalPackagesFolder. Even in that case, we use the SolutionDirectory from DTE for loading NuGet settings. In addition, SolutionManager.IsSolutionOpen and SolutionManager.SolutionDirectory return what DTE returns and do not have overloaded definitions :)

Looks like we have missed the File->New File scenario, where in SolutionManager.IsSolutionOpen is true but, SolutionManager.SolutionDirectory is null. Hence, an attempt to load NuGet settings fail, in case of File->New File scenario. Will fix it

@yishaigalatzer yishaigalatzer added Priority:1 High priority issues that must be resolved in the current sprint. and removed Priority:3 Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog. labels Oct 5, 2015
@yishaigalatzer yishaigalatzer modified the milestones: Commandline 3.2.1, 3.3.0-Beta Oct 5, 2015
yishaigalatzer pushed a commit to NuGetArchive/NuGet.VisualStudioExtension that referenced this issue Oct 5, 2015
@yishaigalatzer
Copy link

This issue seems to be more prominent when Xamarin is installed into Visual Studio 2015. So raising the priority to 0 as it blocks Visual Studio Update I.

The manifestation in this case is that no file can be opened.

@yishaigalatzer
Copy link

Fix was pushed into the 3.2.1 branch, and the PR is open on 3.3, waiting for 3.3 branch to open

@yishaigalatzer
Copy link

Resolved with NuGet/NuGet.Client@d4a128f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority:1 High priority issues that must be resolved in the current sprint. Type:Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants