diff --git a/src/Compilers/Core/CodeAnalysisTest/MetadataReferences/ModuleMetadataTests.cs b/src/Compilers/Core/CodeAnalysisTest/MetadataReferences/ModuleMetadataTests.cs index 188fbb8e333483bee0699e86b8d39c7ec0c998de..c00e276fcba78ed2bb980f25295f6b36ca7ac7b3 100644 --- a/src/Compilers/Core/CodeAnalysisTest/MetadataReferences/ModuleMetadataTests.cs +++ b/src/Compilers/Core/CodeAnalysisTest/MetadataReferences/ModuleMetadataTests.cs @@ -83,9 +83,7 @@ public void CreateFromFile() Assert.Throws(() => ModuleMetadata.CreateFromFile(@"c:\*")); char systemDrive = Environment.GetFolderPath(Environment.SpecialFolder.Windows)[0]; - Assert.Throws(() => ModuleMetadata.CreateFromFile(@"http://goo.bar")); - Assert.Throws(() => ModuleMetadata.CreateFromFile(@"\\.\COM1")); - + Assert.Throws(() => ModuleMetadata.CreateFromFile(@"http://goo.bar")); Assert.Throws(() => ModuleMetadata.CreateFromFile(systemDrive + @":\file_that_does_not_exists.dll")); Assert.Throws(() => ModuleMetadata.CreateFromFile(systemDrive + @":\directory_that_does_not_exists\file_that_does_not_exists.dll")); Assert.Throws(() => ModuleMetadata.CreateFromFile(systemDrive + @":\" + new string('x', 1000))); diff --git a/src/Compilers/Core/Portable/FileSystem/FileUtilities.cs b/src/Compilers/Core/Portable/FileSystem/FileUtilities.cs index 5ca6bdbebff306b90b6636e547572a2b01746e39..cbfedf22b4ebca25dea6af4a5121352e917094d1 100644 --- a/src/Compilers/Core/Portable/FileSystem/FileUtilities.cs +++ b/src/Compilers/Core/Portable/FileSystem/FileUtilities.cs @@ -405,13 +405,12 @@ internal static Stream OpenFileStream(string path) { throw; } - catch (IOException e) + catch (DirectoryNotFoundException e) + { + throw new FileNotFoundException(e.Message, path, e); + } + catch (IOException) { - if (e.GetType().Name == "DirectoryNotFoundException") - { - throw new FileNotFoundException(e.Message, path, e); - } - throw; } catch (Exception e) diff --git a/src/VisualStudio/Core/Def/Implementation/GenerateType/GenerateTypeDialogViewModel.cs b/src/VisualStudio/Core/Def/Implementation/GenerateType/GenerateTypeDialogViewModel.cs index ce3a6a02efe8d2cf89406716a345e2da10c198cf..0a7087132b2302fd0fc61f9f83b05c508788fb0e 100644 --- a/src/VisualStudio/Core/Def/Implementation/GenerateType/GenerateTypeDialogViewModel.cs +++ b/src/VisualStudio/Core/Def/Implementation/GenerateType/GenerateTypeDialogViewModel.cs @@ -288,27 +288,7 @@ internal bool TrySubmit() { this.FullFilePath = Path.GetFullPath(this.FullFilePath); } - catch (ArgumentNullException e) - { - SendFailureNotification(e.Message); - return false; - } - catch (ArgumentException e) - { - SendFailureNotification(e.Message); - return false; - } - catch (SecurityException e) - { - SendFailureNotification(e.Message); - return false; - } - catch (NotSupportedException e) - { - SendFailureNotification(e.Message); - return false; - } - catch (PathTooLongException e) + catch (Exception e) { SendFailureNotification(e.Message); return false; @@ -319,7 +299,11 @@ internal bool TrySubmit() if (lastIndexOfSeparatorInFullPath != -1) { var fileNameInFullPathInContainers = this.FullFilePath.Split(new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries); - this.FullFilePath = string.Join("\\", fileNameInFullPathInContainers.Select(str => str.TrimStart())); + + // Trim spaces of each component of the file name. + // Note that path normalization changed between 4.6.1 and 4.6.2 and GetFullPath no longer trims trailing spaces. + // See https://blogs.msdn.microsoft.com/jeremykuhne/2016/06/21/more-on-new-net-path-handling/ + this.FullFilePath = string.Join("\\", fileNameInFullPathInContainers.Select(str => str.Trim())); } string projectRootPath = null;