From 06eb0f1cfc239528d201bd6a33e227a323fc2de3 Mon Sep 17 00:00:00 2001 From: Yishai Galatzer Date: Mon, 12 Oct 2015 11:00:14 -0700 Subject: [PATCH] Fix https://github.com/NuGet/Home/issues/1550 By throwing an exception with a usefull error message, that would unblock the user. --- .../Runtime/BindingRedirectManager.cs | 33 ++++++++++++------- .../Strings.Designer.cs | 9 +++++ .../Strings.resx | 3 ++ 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/NuGet.Clients/PackageManagement.VisualStudio/Runtime/BindingRedirectManager.cs b/src/NuGet.Clients/PackageManagement.VisualStudio/Runtime/BindingRedirectManager.cs index 8f1eb7ecc20..9c00a4b0e7b 100644 --- a/src/NuGet.Clients/PackageManagement.VisualStudio/Runtime/BindingRedirectManager.cs +++ b/src/NuGet.Clients/PackageManagement.VisualStudio/Runtime/BindingRedirectManager.cs @@ -198,7 +198,7 @@ private void Save(string configFileFullPath, XDocument document) memoryStream.Seek(0, SeekOrigin.Begin); // MSBuildNuGetProjectSystem.AddFile() can't handle full path if the app.config - // file does not exist in the project yet. This happens when NuGet first creates + // file does not exist in the project yet. This happens when NuGet first creates // app.config in the project directory. In this case, only the file name is passed. var path = configFileFullPath; var defaultConfigFile = Path.Combine( @@ -225,11 +225,11 @@ private static ILookup GetAssemblyBindings(XDocument // We're going to need to know which element is associated with what binding for removal var assemblyElementPairs = from dependentAssemblyElement in assemblyBindingElements - select new - { - Binding = AssemblyBinding.Parse(dependentAssemblyElement), - Element = dependentAssemblyElement - }; + select new + { + Binding = AssemblyBinding.Parse(dependentAssemblyElement), + Element = dependentAssemblyElement + }; // Return a mapping from binding to element return assemblyElementPairs.ToLookup(p => p.Binding, p => p.Element); @@ -243,11 +243,22 @@ private static IEnumerable GetAssemblyBindingElements(XElement runtime private XDocument GetConfiguration(string configFileFullPath) { - return ProjectManagement.XmlUtility.GetOrCreateDocument( - "configuration", - Path.GetDirectoryName(configFileFullPath), - Path.GetFileName(configFileFullPath), - MSBuildNuGetProjectSystem.NuGetProjectContext); + try + { + return ProjectManagement.XmlUtility.GetOrCreateDocument( + "configuration", + Path.GetDirectoryName(configFileFullPath), + Path.GetFileName(configFileFullPath), + MSBuildNuGetProjectSystem.NuGetProjectContext); + } + catch (Exception ex) + { + var errorMessage = string.Format(Strings.Error_WhileLoadingConfigForBindingRedirects, + configFileFullPath, + ex.Message); + + throw new InvalidOperationException(errorMessage, ex); + } } private static void UpdateBindingRedirectElement( diff --git a/src/NuGet.Clients/PackageManagement.VisualStudio/Strings.Designer.cs b/src/NuGet.Clients/PackageManagement.VisualStudio/Strings.Designer.cs index e2cb4d135b0..96e09041480 100644 --- a/src/NuGet.Clients/PackageManagement.VisualStudio/Strings.Designer.cs +++ b/src/NuGet.Clients/PackageManagement.VisualStudio/Strings.Designer.cs @@ -141,6 +141,15 @@ public static string Error_FailedToCreateParentFolder { } } + /// + /// Looks up a localized string similar to Failed to load '{0}', while updating binding redirects. {1}. + /// + public static string Error_WhileLoadingConfigForBindingRedirects { + get { + return ResourceManager.GetString("Error_WhileLoadingConfigForBindingRedirects", resourceCulture); + } + } + /// /// Looks up a localized string similar to Failed to add reference to '{0}'. Please make sure that it is in the Global Assembly Cache.. /// diff --git a/src/NuGet.Clients/PackageManagement.VisualStudio/Strings.resx b/src/NuGet.Clients/PackageManagement.VisualStudio/Strings.resx index 68af7987ed3..77db0be355f 100644 --- a/src/NuGet.Clients/PackageManagement.VisualStudio/Strings.resx +++ b/src/NuGet.Clients/PackageManagement.VisualStudio/Strings.resx @@ -189,4 +189,7 @@ Solution is not saved. Please save your solution before managing NuGet packages. + + Failed to load '{0}', while updating binding redirects. {1} + \ No newline at end of file