diff --git a/src/native/corehost/hostmisc/pal.windows.cpp b/src/native/corehost/hostmisc/pal.windows.cpp index 06070b0b1d5da..40999ab002fe2 100644 --- a/src/native/corehost/hostmisc/pal.windows.cpp +++ b/src/native/corehost/hostmisc/pal.windows.cpp @@ -898,8 +898,12 @@ bool pal::realpath(pal::string_t* path, bool skip_error_logging) } } - // Remove the \\?\ prefix, unless it is necessary or was already there - if (LongFile::IsExtended(str) && !LongFile::IsExtended(*path) && + // Remove the UNC extended prefix (\\?\UNC\) or extended prefix (\\?\) unless it is necessary or was already there + if (LongFile::IsUNCExtended(str) && !LongFile::IsUNCExtended(*path) && str.length() < MAX_PATH) + { + str.replace(0, LongFile::UNCExtendedPathPrefix.size(), LongFile::UNCPathPrefix); + } + else if (LongFile::IsExtended(str) && !LongFile::IsExtended(*path) && !LongFile::ShouldNormalize(str.substr(LongFile::ExtendedPrefix.size()))) { str.erase(0, LongFile::ExtendedPrefix.size());