diff --git a/src/native/corehost/hostmisc/pal.windows.cpp b/src/native/corehost/hostmisc/pal.windows.cpp index 06070b0b1d5da..88e73a6256169 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 prefix (\\?\UNC\) or extended prefix (\\?\) unless it is necessary or was already there + if (LongFile::IsUNCExtended(str) && !LongFile::IsUNCExtended(*path) && !LongFile::ShouldNormalize(*path)) + { + str = *path; + } + else if (LongFile::IsExtended(str) && !LongFile::IsExtended(*path) && !LongFile::ShouldNormalize(str.substr(LongFile::ExtendedPrefix.size()))) { str.erase(0, LongFile::ExtendedPrefix.size());