Applies To.NET Framework 4.6

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://).

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.

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.

More Information

For more information, see Application compatibility in the .NET Framework 4.6.2.

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.