Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

Path.GetDirectoryName and Path.GetPathRoot don't work with URIs when you target the .NET Framework 4.6.2


View products that this article applies to.

Symptoms

When you have a project that explicitly targets the .NET Framework 4.6.2 or that disables the AppContext switch Switch.System.IO.UseLegacyPathHandling, Path.GetDirectoryName() and Path.GetPathRoot() throw an invalid path exception when they are passed a URI (such as http://).

↑ Back to the top


Cause

This issue occurs because the same correctness check for colons that's used for the rest of the Path APIs was incorrectly added to these two APIs, which normally tolerate URI syntax.

↑ Back to the top


Resolution

To work around this issue, remove the URI prefix before you call these APIs. Or, set the AppContext switch Switch.System.IO.UseLegacyPathHandling=true.

The .NET Framework team is working to provide a fix for this issue in the future versions of the product. 

For more information, see the .NET Framework 4.6.2 known issues .

↑ Back to the top


Keywords: kbqfe, kbsurveynew, kbtshoot, kbexpertiseadvanced, kb

↑ Back to the top

Article Info
Article ID : 3181958
Revision : 1
Created on : 1/7/2017
Published on : 8/2/2016
Exists online : False
Views : 328